0

I try to connect from my Java-Application to an existing DB2 Database. My Code looks like a minimal version of the example shown at connect DB2 with Java.

public static void main(String[] argv) {
    try {
        Class.forName("com.ibm.db2.jcc.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");

}

When i run this the following error occurs:

java.lang.ClassNotFoundException: com.ibm.db2.jcc.DB2Driver

What are the requirements to connect to a DB2? I added db2jcc.jar and db2jcc_licence_cisuz.jar to the projects build-path and inside the db2jcc.jar exists an DB2Driver.class.

Do I have to configure sth. else?

2
  • How do you execute your app? What's the full stack trace of the exception? is the DB2Driver.class file in /com/ibm/db2/jcc? Commented Aug 17, 2013 at 13:41
  • Thanks, this was the correct hint: "How do you execute". My mistake all the time was, that I executed the above code inside an maven-based application. All I had to do was to add the jar-files to maven repository and not just right-click my project and add to built-path.. Commented Aug 17, 2013 at 15:33

1 Answer 1

1

As written in my comment above, I had to add the DB2-Dependency as described at http://www.mkyong.com/maven/how-to-include-library-manully-into-maven-local-repository/

This is because of my project-type: maven-based application. Just adding the jar-files to built-path was not enough. I had to add them to the repo and add it into my pom.xml.

Sign up to request clarification or add additional context in comments.

Comments

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.