eclipsejdbcdb2eclipse-juno

Connect to DB2 database in eclipse via jdbc


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.


Solution

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