ClassNotFoundException- while using DB2Driver

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mayurapink
    New Member
    • Jun 2007
    • 7

    #1

    ClassNotFoundException- while using DB2Driver

    Hello, I've been banging my metaphorically banging my head again the wall all day attempting to use a simple servlet to connect to a db2 database and update a table. I eventually run into the Exception you see above.

    I've read a couple of other forum posts from various forums and as far as I can tell I have eveything in order:

    - My classpath is: .;C:\Program Files\SQLLIB\bi n;C:\ServletDev ;C:\tomcat 4.1\common\lib\ servlet.jar;C:\ Program Files\SQLLIB\ja va\db2java.zip; C:\jdk1.3.1_08\ bin;C:\ServletD ev; which I believe incorporates all of the directories I need.

    - I have placed the db2java.zip file containing the proper driver in about every lib directory I could find in my tomcat folders

    - I can make a connection to a database when I am not using a servlet.

    - My servlets do run properly when I am not trying to connect to a database.

    Here is the code for the helper class to my servlet file:

    public class DatabaseUtil
    {
    public static void updateDatabase( String ID, String name)
    throws ClassNotFoundEx ception, SQLException
    {
    Class.forName(" COM.ibm.db2.jdb c.app.DB2Driver ");
    Connection con = DriverManager.g etConnection("j dbc:db2:java");
    Statement stmt = con.createState ment();
    String upString = "INSERT INTO Surtable VALUES ('" + ID + "', '" +
    name + "')";
    stmt.executeUpd ate(upString);
    stmt.close();
    con.close();
    }
    }


    The same using oracle with ojdbc14.jar works fine with appropriate change in code.
    But for db2 it does not!!!!!!! Please help
    Any suggestions would be appreciated.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by mayurapink
    Hello, I've been banging my metaphorically banging my head again the wall all day attempting to use a simple servlet to connect to a db2 database and update a table. I eventually run into the Exception you see above.

    I've read a couple of other forum posts from various forums and as far as I can tell I have eveything in order:

    - My classpath is: .;C:\Program Files\SQLLIB\bi n;C:\ServletDev ;C:\tomcat 4.1\common\lib\ servlet.jar;C:\ Program Files\SQLLIB\ja va\db2java.zip; C:\jdk1.3.1_08\ bin;C:\ServletD ev; which I believe incorporates all of the directories I need.

    - I have placed the db2java.zip file containing the proper driver in about every lib directory I could find in my tomcat folders

    - I can make a connection to a database when I am not using a servlet.

    - My servlets do run properly when I am not trying to connect to a database.

    Here is the code for the helper class to my servlet file:

    public class DatabaseUtil
    {
    public static void updateDatabase( String ID, String name)
    throws ClassNotFoundEx ception, SQLException
    {
    Class.forName(" COM.ibm.db2.jdb c.app.DB2Driver ");
    Connection con = DriverManager.g etConnection("j dbc:db2:java");
    Statement stmt = con.createState ment();
    String upString = "INSERT INTO Surtable VALUES ('" + ID + "', '" +
    name + "')";
    stmt.executeUpd ate(upString);
    stmt.close();
    con.close();
    }
    }


    The same using oracle with ojdbc14.jar works fine with appropriate change in code.
    But for db2 it does not!!!!!!! Please help
    Any suggestions would be appreciated.
    If you use the same connection strings successfully when not using servlets, then the problem is a classpath problem...

    Comment

    • jeffbroodwar
      New Member
      • Oct 2006
      • 118

      #3
      Hi,

      Are you sure it's a .zip file? can you check the contents of that file... try if you can find a .jar file instead then paste it in your classpath.... it should work....


      Best Regards,
      Jeff

      Comment

      Working...