3 Replies Latest reply: Oct 11, 2013 4:25 AM by ChrisJenkins RSS

    JDBC connection to Timesten database

    PACHAURI ABHISHEK

      Hi

       

      I am try to write a simple program in java to connect Timesten database.But following exception occured at run time

       

      Exception in thread "main" java.lang.NoClassDefFoundError: TestTimesTen/class

      Caused by: java.lang.ClassNotFoundException: TestTimesTen.class

              at java.net.URLClassLoader$1.run(URLClassLoader.java:202)

              at java.security.AccessController.doPrivileged(Native Method)

              at java.net.URLClassLoader.findClass(URLClassLoader.java:190)

              at java.lang.ClassLoader.loadClass(ClassLoader.java:306)

              at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)

              at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

      Could not find the main class: TestTimesTen.class.  Program will exit.

       

       

      Program :-

       

       

      import java.sql.DriverManager;

      import java.sql.Connection;

      import java.sql.*;

      public class TestTimesTen {

      public static void main(String[] args) {

      try {

      Class.forName("com.timesten.jdbc.TimesTenDriver");

      String URL = "jdbc:timesten:client:DSN=LL_DSN;TCP_PORT=53397";

      Connection _Connection = DriverManager.getConnection(URL);

      Statement stmt = _Connection.createStatement();

      ResultSet rs = stmt.executeQuery(" SELECT * FROM ORDERS ");

      while (rs.next()){

      System.out.println( rs.getInt(1)+"," + rs.getString(2));

      }

      System.out.println("Test Completed");

      }

      catch (SQLException ex) {

      ex.printStackTrace();

      }

      catch (ClassNotFoundException ex) {

      ex.printStackTrace();

      }

      }

      }

       

       

       

      Please help


        • 1. Re: JDBC connection to Timesten database
          jspalmer

          A couple of tips:


          a) Make sure that the compiled class file exists in current directory.
          b) Make sure that the current directory is included in your CLASSPATH environment variable setting.

          • 2. Re: JDBC connection to Timesten database
            PACHAURI ABHISHEK

            Yes there is some problem in CLASSPATH ,After changing this the code is compiled successfully

            But following error occured

             

             

            java.lang.ClassNotFoundException: com.timesten.jdbc.TimesTenDriver

                    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)

                    at java.security.AccessController.doPrivileged(Native Method)

                    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)

                    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)

                    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)

                    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

                    at java.lang.Class.forName0(Native Method)

                    at java.lang.Class.forName(Class.java:169)

                    at TestTimesTen.main(TestTimesTen.java:7)

             

            Please suggest

            • 3. Re: JDBC connection to Timesten database
              ChrisJenkins

              The TimesTen JDBC driver is a JDBC/ODBC bridge and so at runtime it needs to load the TimesTen ODBC driver which is a native code library located in <tt_install_dir>/lib (Unix/Linux) or <tt_install_dir>/bin (WIndows). So, your JVM needs to be able to locate that library. This means that you must be sure to include <tt_install_dir>/lib in your LD_LIBRARY_PATH environment variable (Unix/Linux) or <tt_install_dir>/bin in your PATH environment variable (Windows).

               

              An easy way to ensure that your environment is setup properly is to use the relevant environment script located in <tt_install)dir>/bin - ttenv.sh for Bourne shell on Unix/Linux for example.

               

              Chris