mysql connector in linux - java.lang.ClassNotFoundException: com.mysql.jdbc

I use mysql-connector-java-5.0.6-bin.jar and j2eesdk-1_4_03-linux.bin.

I created a new directory: /usr/java/javaclass.

The CLASSPATH variable point to this directory, where I copied the mysql-connector-java-5.0.6-bin.jar file.

In the same directory I have the .java file that I test with.

I compile without error /usr/java/jdk/bin/javac Jdbc11.java.

And I try to run, but with errors: /usr/java/jdk/bin/java -cp . Jdbc11

The complete error is:

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

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

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

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

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

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

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

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

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

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

at Jdbc11.main(Jdbc11.java:8)

Where is the problem?

Thank you.

[1195 byte] By [Victorqeda] at [2007-11-15]
# 1
> The CLASSPATH variable point to this directory, where> I copied the mysql-connector-java-5.0.6-bin.jarThe CLASSPATH should contain the full path of the jar, not just the directory that contains the jar.
sabre150a at 2007-7-12 > top of java,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
I tryed that too.This is the CLASSPATH now.declare -x CLASSPATH="/usr/java/javaclass/mysql-connector-java-5.0.6-bin.jar"But I receive the same error.
Victorqeda at 2007-7-12 > top of java,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

This is the test class:

import java.sql.*;

public class Jdbc11 {

public static void main(String args[]){

try {

Class.forName("com.mysql.jdbc.Driver");

String url = "jdbc:mysql://192.168.250.16:3306/mysql";

Connection con = DriverManager.getConnection(url,"test", "test");

con.close();

} catch( Exception e ) {

e.printStackTrace();

}

}

}

Victorqeda at 2007-7-12 > top of java,Database Connectivity,Java Database Connectivity (JDBC)...
# 4
What shell are you using?After setting your CLASSPATH, Print and post your CLASSPATH usingecho $CLASSPATHMessage was edited by: sabre150
sabre150a at 2007-7-12 > top of java,Database Connectivity,Java Database Connectivity (JDBC)...
# 5

The shell is bash from a Centos 5.

[root@ambratest javaclass]# echo $CLASSPATH

/usr/java/javaclass/mysql-connector-java-5.0.6-bin.jar

The file is defenetly there.

I made a "cat /usr/java/javaclass/mysql-connector-java-5.0.6-bin.jar" and it displays the contents of the file.

Victorqeda at 2007-7-12 > top of java,Database Connectivity,Java Database Connectivity (JDBC)...
# 6

> And I try to run, but with errors:

> /usr/java/jdk/bin/java -cp . Jdbc11

This says 'ignore the CLASSPATH environment variable and just use this current directory'. You need

usr/java/jdk/bin/java -cp .:$CLASSPATH Jdbc11

or you need to add '.' to the CLASSPATH and then just use

java Jdbc11

sabre150a at 2007-7-12 > top of java,Database Connectivity,Java Database Connectivity (JDBC)...
# 7
Thank you.Both solutions worked.
Victorqeda at 2007-7-12 > top of java,Database Connectivity,Java Database Connectivity (JDBC)...