Reputation: 7705
Trying to work with a JDBC connection to Teradata. I've loaded the tdgssconfig.jar and terajdbc4.jar file and adding them to the classpath with javac when I compile in Linux. But I still get a ClassnotFoundException when trying to compile.
I've not worked with java in a while, but I've scoured the net and it looks like it should work.
Simple Code:
import java.sql.*;
class TDtest {
public static void main(String[] args) {
System.out.println(classpath);
Class.forName("com.teradata.jdbc.TeraDriver");
}
}
*.jars are definitely there:
[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
verbose error log - it looks like the classpath is right to me:
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");
I've tried un-jar'ing the jdbc jar's and they definitely have com/teradata/jdbc/TeraDriver.class in them.
I'm at a loss. Any idea what I'm doing wrong?
Upvotes: 1
Views: 14094
Reputation: 5868
I had a ClassNotFoundException with version 16.20.00.06. I switched to 15.10.00.37 It works now. My guess is the 16.20.00.06 works with a newer version of Java than I have.
Upvotes: 0
Reputation: 2309
I got this
Exception in thread "main" java.lang.ClassNotFoundException:
com.ncr.teradata.TeraDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:191)
at com.ebay.quality.bp.Z_Query_Teradata.main(Z_Query_Teradata.java:15)
When I checked my pom.xml file under Dependency Hierarchy tab, I found out that I had test next to the dependency.
<dependency>
<groupId>com.thirdparty.teradata</groupId>
<artifactId>terajdbc4</artifactId>
<version>14.10.00.17</version>
<scope>test</scope>
</dependency>
I removed the line with test scope and it worked.
Upvotes: 0
Reputation: 6572
Try this
try {
Class.forName("com.teradata.jdbc.TeraDriver").newInstance();
} catch (Exception e) {
e.printStackTrace();
}
Upvotes: 0
Reputation: 159844
The compiler is not looking for the class com.teradata.jdbc.TeraDriver
from your jar file, it is reacting to the Class.forName()
statement.
As Class.forName()
throws ClassNotFoundException
which is a checked exception, you will need to handle it.
You could either surround the exception in a `try/catch' block or throw the exception to compile:
class TDtest {
public static void main(String[] args) {
System.out.println(classpath);
try {
Class.forName("com.teradata.jdbc.TeraDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
// more error handling..
}
}
}
Upvotes: 2
Reputation: 4313
The problem isnt about your classpath. Just that you would want to wrap your Class.forName line with a try/catch block and catch the checked exception ClassNotFoundException
Upvotes: 0