Thanks for looking at this post. I am a
java newbie and thought I had things under control, however, guess not, and any of the postings that make sense have things I had already applied. I am using Windows XP and I am using the JVM and a simple class to
test a mySQL connection.
I have downloaded the mysql-connector-java-3.0.10-stable-bin.jar and have place it in my c:\j2sdk1.4.2_03\jre\lib\ext\ location.
Here is my CLASSPATH environment variable value:
c:\j2sdk1.4.2_03\lib\tools.jar;c:\j2sdk1.4.2_03\jre\lib\ext\mysql-connector-java-3.0.10-stable-bin.jar;
Are there other settings I must change? The main issue here is that it cannot seem to find the .jar!?!?! I am using the following code that other postings helped me with and I get the following stack trace:
Thanks so much for your help in advance!
/*
* Created on Feb 15, 2004
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package client;
import java.sql.*;
public class JDBCExample {
public static void main(
String[] args) {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception E) {
System.err.println("Unable to load driver.");
E.printStackTrace();
}
try {
Connection C = DriverManager.getConnection("jdbc:mysql://localhost:53345/mysql","root","13004433");
// or Connection C = DriverManager.getConnection("jdbc:mysql://csci571.usc.edu:53345/mysql","root","13004433");
// or Connection C = DriverManager.getConnection("jdbc:mysql://csci571.usc.edu:53345/mysql?user=root&password=13004433");
// or Connection C = DriverManager.getConnection("jdbc:mysql://localhost:53345/mysql?user=root&password=13004433");
//
// Replace the PORT number (53345 in this example) by the port number on which your MySQL demon is running,
// replace the DATABASENAME (mysql in this example) with your database name
// replace USER with your user name and PASSWORD with your password and
// use csci571.usc.edu if that is where MySQL is running for you.
// In most case "localhost" will also work. See what you get if you run
// the SQL command "SELECT * FROM user" from the MySQL command line interface
// and use what you see under "Host".
Statement s=C.createStatement();
String sql="select * from user"; // Put your SQL statement here
s.execute(sql);
ResultSet res=s.getResultSet();
if (res!=null) {
while(res.next()) { //note MySql start with the index 1 as the first column
System.out.println("\n"+res.getString(1)+"\t"+res.getString(2));
}
}
} catch (SQLException E) {
System.out.println("SQLException: " + E.getMessage());
System.out.println("SQLState: " + E.getSQLState());
System.out.println("VendorError: " + E.getErrorCode());
}
}
}
STACK TRACE:
Unable to load 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 client.JDBCExample.main(JDBCExample.java:14)
SQLException: No suitable driver
SQLState: 08001
VendorError: 0