Hi,
I am relativly new to
java, I only been programiming for about 4/5 months,
I am trying to
test a simple connection to a mysql database but I keep getting the same error.
I downloaded and saved the file mysql-connector-java-3.0.10-stable-bin.jar to following directory on c ..
C:\j2sdk1.4.1_01\jre\lib\ext\mysql-connector-java-3.0.10-stable-bin.jar
I then changed the classpath to reflect the following
%CATALINA_HOME%\common\lib\servlet.jar;C:\j2sdk1.4.1_01\jre\lib\ext\mysql-connector-java-3.0.10-stable-bin.jar;
When I run the following code i continue to receive the error
C:\>java TestQuery
ClassNotFoundException: com.jdbc.mysql.jdbcDriver
Trying to connect...
SQLException: No suitable driver
import java.sql.*;
public class TestQuery {
public TestQuery () {
}
public static void main(
String args[]) {
String url="jdbc://localhost/publish";
Connection con;
String query = "SELECT * FROM book";
Statement stmt;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
}
catch (java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
System.out.println("Trying to connect...");
con = DriverManager.getConnection (url, "publish", "wrox");
System.out.println("connected!");
stmt = con.createStatement();
ResultSet result = stmt.executeQuery(query);
while (result.next()) {
String name = result.getString(1) + " " + result.getString(2);
System.out.println(name);
}
stmt.close();
con.close();
}
catch(SQLException ex) {
System.err.print("SQLException: ");
System.err.println(ex.getMessage());
}
}
}
Can you please advise,
Do i need to import a packae and if so what package:
The tables have been set up and the database "publish" with the username and password have also been set up properly.
The strange thing is that I wrote a
jsp file to update this database and it worked ok , so this leads me to belive that I have properly referenced somEthing in the above code.
PLEASE ADVISE.