我正在尝试通过 JDBC 使用 Eclipse(Juno 版)连接到 IBM DB2 数据库.我已将驱动程序(外部 jar 文件)添加到我的项目中,并且驱动程序已正确加载...
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");
}
我也知道连接数据(数据库路径、用户名、密码)是正确的.但我得到一个 java.lang.NoClassDefFoundError:
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.
我遇到了同样的错误.我使用 java 8 运行它,我切换到 Java 7 并且它工作正常.
I was getting the same error. I was running it using java 8, I switched to Java 7 and it worked.
这篇关于在eclipse中通过jdbc连接DB2数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!