6 Replies Latest reply on Dec 24, 2002 3:39 AM by 843854

    Need Help Loading Sqlbase Driver Using Class.forName(...

    843854
      I'm having trouble connecting to a Sqlbase database on my PC. The problem seems to be with loading the driver with the "Class.forName" method. My source code (listed below) is in the "C:\My Documents\java" folder. I installed the Sqlbase driver in "C:\com\centurasoft\java\sqlbase" folder. The driver installation modified my autoexec.bat file to include the line "SET CLASSPATH=C:\com\centurasoft\java\sqlbase".
      The epdmo database is in a folder on my D:\ drive.

      It seems to find the SqlbaseDriver.class file, but for some reason it can't load it. I would greatly appreciate any suggestions as to how I can fix this.

      With the line -- Class.forName("centura.java.sqlbase.SqlbaseDriver");
      The SqlbaseEx.java program will compile, but I get the following error
      when I try to run it:

      Exception in thread "main" java.lang.NoClassDefFoundError: SqlbaseDriver (wrong name: com/centurasoft/java/sqlbase/SqlbaseDriver)
      at java.lang.ClassLoader.defineClass0(Native Method)
      at java.lang.ClassLoader.defineClass(Unknown Source)
      ...
      ... [several more lines like these]
      ...
      at SqlbaseEx.main(SqlbaseEx.java:25)




      With the line -- DriverManager.registerDriver(new SqlbaseDriver());
      The SqlbaseEx.java program will NOT compile. I get the following error:

      SqlbaseEx.java:21: cannot access SqlbaseDriver
      bad class file: C:\com\centurasoft\java\sqlbase\SqlbaseDriver.class
      class file contains wrong class: com.centurasoft.java.sqlbase.SqlbaseDriver
      Please remove or make sure it appears in the correct subdirectory of the classpath.


      Also, does the line -- String url = "jdbc:sqlbase:epdmo";
      look OK? I've seen numerous examples and they all have some values separated by slashes //. Am I
      missing something here that will bite me when I get past this driver loading error?


      import java.sql.*;

      // Create the ...
      public class SqlbaseEx {

      public static void main(String args[]) {

      String url = "jdbc:sqlbase:epdmo";
      Connection con;
      String createString;
      createString = "create table COFFEES " +
      "(COF_NAME varchar(32), " +
      "SUP_ID int, " +
      "PRICE float, " +
      "SALES int, " +
      "TOTAL int)";
      Statement stmt;

      try {
      Class.forName("centura.java.sqlbase.SqlbaseDriver");
      // DriverManager.registerDriver(new SqlbaseDriver());

      } catch(java.lang.ClassNotFoundException e) {
      System.err.print("ClassNotFoundException: ");
      System.err.println(e.getMessage());
      }

      try {
      con = DriverManager.getConnection(url, "SYSADM", "SYSADM");

      stmt = con.createStatement();
      stmt.executeUpdate(createString);

      stmt.close();
      con.close();

      } catch(SQLException ex) {
      System.err.println("SQLException: " + ex.getMessage());
      }



      }
      }
        • 1. Re: Need Help Loading Sqlbase Driver Using Class.forName(...
          843854
          With the line --
          Class.forName("centura.java.sqlbase.SqlbaseDriver");
          The SqlbaseEx.java program will compile, but I get the
          following error
          when I try to run it:

          Exception in thread "main"
          java.lang.NoClassDefFoundError: SqlbaseDriver (wrong
          name: com/centurasoft/java/sqlbase/SqlbaseDriver)
          at java.lang.ClassLoader.defineClass0(Native
          e Method)
          at java.lang.ClassLoader.defineClass(Unknown
          n Source)
          You're specifying "centura.java.sqlbase.SqlbaseDriver" for the driver class name but the error message seems to be telling you that it is actually "com.centurasoft.java.sqlbase.SqlbaseDriver".

          Col
          • 2. Re: Need Help Loading Sqlbase Driver Using Class.forName(...
            843854
            Thanks for the reply.
            Upon further testing, I think my original post was slightly incorrect: if I use either of the following lines --
            Class.forName("com.centurasoft.java.sqlbase.SqlbaseDriver");
            or
            Class.forName("centura.java.sqlbase.SqlbaseDriver");

            I get the following error at runtime:
            ClassNotFoundException: com.centurasoft.java.sqlbase.SqlbaseDriver
            or
            ClassNotFoundException: centura.java.sqlbase.SqlbaseDriver

            It is when I use the line -- Class.forName("SqlbaseDriver");
            that I get the long error message in my original post.

            I don't understand why it can't find/load the driver. I feel like I've covered all the bases -- I've tried numerous variations of the driver name in the Class.forName method, my classpath variable seems to be set correctly. Does it matter what folder I compile my program in? Right now, I've just been compiling it in the same folder as the driver file -- c:\com\centurasoft\java\sqlbase.
            • 3. Re: Need Help Loading Sqlbase Driver Using Class.forName(...
              843854
              If you go to this forum http://forum.java.sun.com/forum.jsp?forum=54 and do a search on ClassNotFoundException you should find an answer.

              Col

              • 4. Re: Need Help Loading Sqlbase Driver Using Class.forName(...
                843854
                You were right about the driver name. The problem was with my classpath setting. I had to change it to include c:\ so it could find com.centurasoft.java.sqlbase.

                Now, I'm getting the error:
                SQLException: SqlbaseSession(): failure to connect to host:

                I think my URL string is wrong. Any suggestions?
                • 5. Re: Need Help Loading Sqlbase Driver Using Class.forName(...
                  843854
                  Check the documentation that came with your driver. Each driver can have a slightly different syntax for the URL. You'll probably have to specify the server and database in some fashion.

                  Col
                  • 6. Re: Need Help Loading Sqlbase Driver Using Class.forName(...
                    843854

                    Hi,

                    I have come at the same stage as you for connecting to the SQLBase database. I am also getting:

                    java.sql.SQLException: SqlbaseSession(): failure in connection of host!

                    I get this exception when I try to get a connection:

                    Connection conn = DriverManager.getConnection("jdbc:sqlbase://mmo79/island", "SYSADM", "SYSADM");

                    It will be great if you can tell me how did you fix the above exception which you also seem to be getting.