Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JDBC Help - for MySQL 1

Status
Not open for further replies.

jeanpierre

Technical User
Jun 14, 2001
137
CA
I have a problem loading the database driver for MySQL.

OS : Win XP (Home)
Database : MySQL
JDBC Driver : MM.MySQL

What I did to install the driver : I un-archived the distribution .jar archive,
you can install the driver in two ways-

1) When to Control Panel|Systems|Advance|Environment Variables and entered the path to the org subdirectory of the downloaded folder - C:\mm.mysql-2.0.11\org

2) To be doubly safe, I added mm.mysql-2.0.11-bin.jar folder to C:\j2SDK1.4.0\jre\lib\ext

Here is the code I used to establish a connection. The database is called "test":

import java.sql.*;

public class ConnecTion{

public static void main(String args[])
{

Connection connection;
try {
Class.forName("org.gjt.mm.mysql.Driver");
String url = "jdbc:mysql://localhost/test";
String username = "dillinger";
String password = "master";
connection = DriverManager.getConnection(url, username, password);
}
catch (ClassNotFoundException e) {
System.err.println("Could not load database driver!");
}
catch (SQLException e) {
System.err.println("Could not connect to the database!");
}
}
}


The errors message I receive is "Cannot load database driver!"


Are there any suggestions?

Thanks.
 
if the program is called connect type this in the dos box
java -cp ".;C:/j2SDK1.4.0/jre/lib/ext/mm.mysql-2.0.11-bin.jar" connect . The part after the -cp must be the absolute or relative address to the driver. You need the ".;C:\..." before it aswell.

Try the slashes both ways, can't remember which is correct.
You need to end the line
Class.forName("org.gjt.mm.mysql.Driver").newInstance()
in your code instead of the line you have after the try

Hope this helps
 
The only jars that you can put in the lib/ext directory are java extensions (i.e. begin with javax.*).

You need to add the driver to your CLASSPATH not your PATH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top