Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

mysql connector/j classpath again

843854Mar 1 2004 — edited Mar 3 2004
Hi, I'm having problems using the classpath. I'm running JDK 1.4.2, Win2k, mysql 4.0.18, and connector/j 3.0.11. I'm also using cygwin as my shell environment. Below is a copy of my program. I've tried running my program with the CLASSPATH env. variable set to ".:/cygdrive/c/mysql/java/mysql-connector-java-3.0.11-stable/mysql-connector-java-3.0.11-stable-bin.jar". Then I've tried not having that set and compiling the prog with the classpath option to the same jar file. And I've also tried not having the env. variable set, not using the classpath option while compiling but instead using "java -cp <path to jar> LoadDriver". In all of these cases I've had one of the two results:

Exception in thread "main" java.lang.NoClassDefFoundError: LoadDriver

or

we are now working...
starting
Unable to get instance of com.mysql.jdbc.Driver
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at LoadDriver.main(LoadDriver.java:12)

Either way, it looks like a CLASSPATH issue. I've read a lot of previous threads on this topic and made sure that the *.class files are in the jar file. I've tried using an older version of connector/j. I've tried putting the jar file in the jre/lib/ext/ dir. Nothing seems to work. Any ideas? I'm concerned that the cygwin path style might screw things up.

Thanks in advance!
import java.sql.* ;

public class LoadDriver 
{ 
  public static void main(String[] args) 
  { 
    Connection conn = null ;
    System.out.println("we are now working...") ;
    try 
    { 
      System.out.println("starting") ;
      Class.forName("com.mysql.jdbc.Driver").newInstance(); 
      conn = DriverManager.getConnection("jdbc:mysql://localhost/java");

      if ( conn != null )
      {
        System.out.println ("We have established a connection") ;
      }
    } 
    catch (SQLException ex) 
    { 
      // handle the error 
      System.err.println("SQL  state: " + ex.getSQLState());            
      System.err.println("Error code: " + ex.getErrorCode());            
      System.out.println("VendorError: " + ex.getErrorCode()); 
      ex.printStackTrace();
    }
    catch (Exception ex)
    {
      System.out.println("Unable to get instance of " + ex.getMessage()) ;
      ex.printStackTrace();
    }
  }
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 31 2004
Added on Mar 1 2004
2 comments
325 views