Skip to content
Advertisement

Teradata and JDBC driver – classnotfoundexception …but its there?

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?

Advertisement

Answer

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..
      }
   }
}
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement