0

I don't know how to set the classpath in a java project.

This is the code that I run:

try { Class.forName("com.ibm.db2.jdbc.app.DB2Driver");
        }  catch (ClassNotFoundException e) {
            System.out.println("Please include Classpath  Where your DB2 Driver is located");
            e.printStackTrace();
            return;
        } System.out.println("DB2 driver is loaded successfully");
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rset=null;
        boolean found=false;
        try {
            conn = DriverManager.getConnection("jdbc:db2:DB2PDBA","USERID","PASSWORD");
            if (conn != null)
            {
                System.out.println("DB2 Database Connected");
            }
            else
            {
                System.out.println("Db2 connection Failed ");
            }

and my Error is:

java.lang.ClassNotFoundException: com.ibm.db2.jdbc.app.DB2Driver

1 Answer 1

1

When we say put something within classpath, it means:

you should put the related jar files that your app needs to run the entire application somewhere in your project.

Please follow the link below to create a DB2 application -> IBM Example about DB2

The only thing you need to do is to:

  1. Add this into your project
  2. change the credentials and db information
  3. add the db2 jdbc jar file to your project
Sign up to request clarification or add additional context in comments.

13 Comments

After including the jar in build path still getting the error--> java.lang.ClassNotFoundException: com.ibm.db2.jdbc.app.DB2Driver
@Shiv try this -> Class.forName("com.ibm.db2.jcc.DB2Driver"); The url is different
Thanks Mehdi....This time driver is loaded but got below error in establishing the connection- com.ibm.db2.jcc.am.SqlException: [jcc][10389][12245][3.62.57] Failure in loading native library db2jcct2, java.lang.UnsatisfiedLinkError: C:\Program Files (x86)\IBM\SQLLIB\BIN\db2jcct2.dll: Can't load IA 32-bit .dll on a AMD 64-bit platform: ERRORCODE=-4472, SQLSTATE=null
@Shiv iwm.dhe.ibm.com/sdfdl/v2/regs2/smkane/IDSDIS/Xa.2/… Try downloading the driver using this link. Then you should try the jars inside the zip file
@Mehdi- still the same error- Failure in loading native library db2jcct2, java.lang.UnsatisfiedLinkError: C:\Program Files (x86)\IBM\SQLLIB\BIN\db2jcct2.dll: Can't load IA 32-bit .dll on a AMD 64-bit platform: ERRORCODE=-4472, SQLSTATE=null
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.