Discussions

Web tier: servlets, JSP, Web frameworks: Tomcat DataSource

  1. Tomcat DataSource (2 messages)

    Hi,
       I am using tomcat 4.1 and Oracle 8i. I am using connection pool which tomcat provides. I have a requirement to login into database using the user Id and Password that the user provides in login screen. This is to verify that the user is a database user. I donot want to use the User Id and Password that is configured in Server.xml while logging in. Is there any way that I can get the connection using the User's User Id and Password? Please let me know

    Thanks in advance
    Prasanna Kumar K

    Threaded Messages (2)

  2. Tomcat DataSource[ Go to top ]

    your could try getting the datasource from the context then use the
    .getConnection( String username , String password ) on the datasource object and then if the connection is null or a SQLException is thrown you can deal with it
  3. Tomcat DataSource[ Go to top ]

    Hi,
    Assume that the JNDI of the data source is jdbc/OracleDS...
    String id = request.getParameter("userid");
    String passWord = request.getParameter("password");
    InitialContext ctx = new InitialContext();
    DataSource ds = (DataSource)ctx.lookup("jdbc/OracleDS");
    Connection conn = ds.getConnection(id,passWord);
    ....
    //go ahead with the database

    Irshad.