Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2004
    Posts
    5

    Unanswered: JDBC servlet help

    Hi
    I have an application that uses the following code to connect to a DB2 database

    String url = "jdbc:db2:mydb";
    String user = "cstrife";
    String password ="mypass";
    try{
    Class.forName"COM.ibm.db2.jdbc.app.DB2Driver").new Instance();
    DB = DriverManager.getConnection(url, user, password);

    }
    catch(Exception ex){
    out.println(ex.getMessage());
    }

    this works fine, the java app can connect, query and do sql stuff
    but when i try using the same code in a java servlet (using tomcat) - it cant seem to connect
    Do i need another JDBC driver for it work in servlets?
    (DB2 and tomcat are on the same computer)

    Can anyone help me? Thanks

  2. #2
    Join Date
    Feb 2004
    Posts
    24

    Re: JDBC servlet help

    Originally posted by cstrife
    Hi

    you can use the same driver within your servlet. store the unpacked driver within your application context in the folder classes or store the jar-file fo ur driver in the folder lib within your application context.
    You can also store the unpacked driver within the shared/classes folder or the jar-file within the shared/lib folder. If u placed the driver in the shared folder all applications running under ur tomcat can use the driver.
    For more information see the http://localhost:8080/index.jsp -> Tomcat documantation -> class loader.

    hope this helps a bit

    Marc Gaines

    Hi
    I have an application that uses the following code to connect to a DB2 database

    String url = "jdbc:db2:mydb";
    String user = "cstrife";
    String password ="mypass";
    try{
    Class.forName"COM.ibm.db2.jdbc.app.DB2Driver").new Instance();
    DB = DriverManager.getConnection(url, user, password);

    }
    catch(Exception ex){
    out.println(ex.getMessage());
    }

    this works fine, the java app can connect, query and do sql stuff
    but when i try using the same code in a java servlet (using tomcat) - it cant seem to connect
    Do i need another JDBC driver for it work in servlets?
    (DB2 and tomcat are on the same computer)

    Can anyone help me? Thanks

  3. #3
    Join Date
    Mar 2004
    Posts
    5
    I have the jar file thats in the DB2 directory in my class path
    do i take that out of my classpath
    or do i just leave that there and have 2 copies
    that one and the one in the tomcat directory?

    thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •