尝试使用与 Teradata 的 JDBC 连接。当我在 Linux 中编译时,我已经加载了 tdgssconfig.jar 和 terajdbc4.jar 文件并使用 javac 将它们添加到类路径中。但是在尝试编译时我仍然得到一个 ClassnotFoundException 。
我有一段时间没有使用 java 了,但是我已经搜索了网络,看起来它应该可以工作。
简单代码:
import java.sql.*;
class TDtest {
public static void main(String[] args) {
System.out.println(classpath);
Class.forName("com.teradata.jdbc.TeraDriver");
}
}
*.jars 肯定存在:
[user1@box java]# ls -l /home/user1/test/java/libs/*
-rwxrwxrwx 1 user1 user1 2405 Oct 26 12:00 /home/user1/test/java/libs/tdgssconfig.jar
-rwxrwxrwx 1 user1 user1 873860 Oct 26 12:00 /home/user1/test/java/libs/terajdbc4.jar
详细的错误日志 - 看起来类路径对我来说是正确的:
javac -verbose -cp ".:/home/user1/test/java/libs/tdgssconfig.jar:/home/user1/test/java/libs/terajdbc4.jar" TDtest.java
[parsing started TDtest.java]
[parsing completed 21ms]
[search path for source files: .,/home/user1/test/java/libs/tdgssconfig.jar,/home/user1/test/java/libs/terajdbc4.jar]
[search path for class files: /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/resources.jar,/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/rt.jar,/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/sunrsasign.jar,/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/jsse.jar,/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/jce.jar,/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/charsets.jar,/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/classes,/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/ext/dnsns.jar,/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/ext/sunpkcs11.jar,/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/ext/localedata.jar,/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/ext/gnome-java-bridge.jar,/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/ext/sunjce_provider.jar,.,/home/user1/test/java/libs/tdgssconfig.jar,/home/user1/test/java/libs/terajdbc4.jar]
[loading java/lang/Object.class(java/lang:Object.class)]
[loading java/lang/String.class(java/lang:String.class)]
[checking TDtest]
[loading java/lang/Class.class(java/lang:Class.class)]
[loading java/lang/Error.class(java/lang:Error.class)]
[loading java/lang/ClassNotFoundException.class(java/lang:ClassNotFoundException.class)]
[loading java/lang/Exception.class(java/lang:Exception.class)]
[loading java/lang/Throwable.class(java/lang:Throwable.class)]
[loading java/lang/RuntimeException.class(java/lang:RuntimeException.class)]
TDtest.java:4: unreported exception java.lang.ClassNotFoundException; must be caught or declared to be thrown
Class.forName("com.teradata.jdbc.TeraDriver");
我试过 un-jar'ing jdbc jar,它们肯定有 com/teradata/jdbc/TeraDriver.class。
我不知所措。知道我做错了什么吗?