Connect to DB2 database in eclipse via jdbc

25,705

Solution 1

I was getting the same error. I was running it using java 8, I switched to Java 7 and it worked.

Solution 2

What Version of driver do you use? I encountered the same problem with Java 1.8 and driver version 2 (named db2jcc.jar). Using the driver version 4 (named db2jcc4.jar) it works flawlessly. Be sure, when using e.g. tomcat, that only the right driver is persistent in the lib-directory. If both drivers are persistent, it will strictly use the old one (version 2).

Solution 3

Try to use the direct connection from the driver, having the same classpath and user. In this way you can ensure that your environment is correctly configured, and the problem is from Java.

http://pic.dhe.ibm.com/infocenter/db2luw/v10r5/topic/com.ibm.db2.luw.apdv.java.doc/src/tpc/imjcc_rjv00004.html

java com.ibm.db2.jcc.DB2Jcc -url jdbc:db2://mysys.myloc.svl.ibm.com:446/MYDB -user db2user -password db2pass -tracin

You can even configure this line in Eclipse, by passing the parameters in the "Run..." dialog, and using the same classpath as you run your app.

Share:
25,705
mosquito87
Author by

mosquito87

Updated on December 18, 2020

Comments

  • mosquito87
    mosquito87 over 3 years

    I'm trying to connect to an IBM DB2 database with Eclipse (version Juno) via JDBC. I've added the drivers (external jar files) to my project and the driver is loaded correctly ...

    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        Class.forName("com.ibm.db2.jcc.DB2Driver");
        System.out.println("Driver loaded");
    
        Connection dbConn = DriverManager.getConnection("jdbc:db2://***.**.***.*:50000/BWUEBDB", "username", "password");
        System.out.println("Connected");
    }
    

    I also know that the connection data (database path, username, password) is correct. But I get a java.lang.NoClassDefFoundError:

    Exception in thread "main" java.lang.NoClassDefFoundError: sun/io/UnknownCharacterException
        at com.ibm.db2.jcc.b.a.<init>(a.java:238)
        at com.ibm.db2.jcc.b.b.a(b.java:1624)
        at com.ibm.db2.jcc.c.p.a(p.java:350)
        at com.ibm.db2.jcc.c.p.<init>(p.java:404)
        at com.ibm.db2.jcc.b.b.<init>(b.java:256)
        at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:163)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at AppTest.main(AppTest.java:17)
    Caused by: java.lang.ClassNotFoundException: sun.io.UnknownCharacterException
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 9 more
    

    There must be something wrong with the project properties but I really don't know where to look for.