MySQL Driver Class Not Found

MySQL Driver Set Up problems - Class Not Found error

====================================================

I have recently begun conversion of a working Java + MS Access application to Java + MySQL. I get a Class Not Found error trying to set up the driver. I am using MySQL Connection/J 3.0.8.

I have read multiple forum entries as well as the ReadMe in the Connection/J installation and also Mark Matthews web site installation and programming info. I have made many tries to get the code to work.

But I cannot get past the Class Not Found error when trying to set up the DB Driver.

I copied the JAR file "mysql-connector-java-3.0.8-stable-bin.jar" into the Java folder \jdk1.3.1_06\jre. That folder is in my class path.

Got Class Not Found.

Added the file name explicitly in the classpath. Still error.

Tried "com.mysql.jdbc.Driver" as Class.forName. Error.

Tried "org.gjt.mm.mysql.Driver" as Class.forName. Error.

I can't seem to find the correct combination. Help?

Thanks, WBARBEE2

================

Current code is:

SQLDBClass = "com.mysql.jdbc.Driver";

SQLDBName = "jdbc:mysql://localhost/RescForSrs";

--

System.out.println("Load DBClass " + SQLDBClass);

try {

Class.forName(SQLDBClass).newInstance();

}

catch (Exception e)

{

*****Error here*****

ErrMsg = "Error loading JDBC.ODBC Driver";

(display)

return;

}

System.out.println("Set connect " + SQLDBName);

try {

UserConn = DriverManager.getConnection(SQLDBName);

UserRead = UserConn.createStatement();

}

catch (Exception e)

{

ErrMsg = "Error JDBC Connection";

(display)

return;

}

[1776 byte] By [wbarbee2a] at [2007-9-21]
# 1
>I copied the JAR file "mysql-connector-java-3.0.8-stable-bin.jar" into the Java folder \jdk1.3.1_06\jre. That folder is in my class path.Doesn't matter. The jar file has to be in your classpath. Not the folder it's in, the jar file itself.
DrClapa at 2007-7-14 > top of java,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

Thanks again, Dr. C.

In framing a reply to your note, that the JAR WAS in the classpath, I noticed that I had mispelled the name of the JAR. (big fat stupid fingers...)

The program now sails through with no errors.

General question: Is it necessary to put EVERY JAR NAME in the classpath or can they just be put in a FOLDER that is in the classpath?

wbarbee2a at 2007-7-14 > top of java,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

FINAL NOTE FOR DOCUMENTATION

This code worked!

Windows 2000 Professional (WinNT)

MySQL

MySQL Connector/J 3.0.8

1) Added JAR name to CLASSPATH

c:\folder names\mysql-connector-java-3.0.8-stable-bin.jar;

(Be careful, by habit I kept keying . instead of - between the words.)

2) Class name in first command

Class.forName("org.gjt.mm.mysql.Driver").newInstance();

3) Connect name for localhost

Connection UserConn =

DriverManager.getConnection("jdbc:mysql://localhost/DBNAME");

Statement UserRead = UserConn.createStatement();

4) SQL Query and Closes

ResultSet abc = UserRead.executeQuery("select etc.");

if (abc.next())

{

process...

}

UserRead.close();

UserConn.close();

REMEMBER -

All of the items in 2), 3), and 4) are in Try / Catch structures.

wbarbee2a at 2007-7-14 > top of java,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

> General question: Is it necessary to put EVERY JAR

> NAME in the classpath or can they just be put in a

> FOLDER that is in the classpath?

In general yes.

There are exceptions such as the ext directory. Or how J2EE containers or other types of frameworks dynamically load stuff.

jschella at 2007-7-14 > top of java,Database Connectivity,Java Database Connectivity (JDBC)...
# 5
Thanks alot wbarbee2,I'm having trouble in configuring the mysql and jdbc these daysand I found your nice documentationIt's cool and helpful, it works :)
tomotachia at 2007-7-14 > top of java,Database Connectivity,Java Database Connectivity (JDBC)...