• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error: ClassNotFoundException: com.jdbc.mysql.jdbcDriver,"No suitable driver"

 
p Walsh
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your database URL doesn't look correct. "No suitable driver" means the DRiverManager couldn't find a registered Driver that accepts your database URL. As long as the driver was found (which it should be, since you don't see that error), feeding the correct database URL should match it to the correct DRiver.
Try: jdbc:mysql://localhost/publish
Dave
 
p Walsh
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thansk for the advice,
The problem was I left "mysql" out of the url string.
I've now made the nesscary changes and all is fine.
Thanks again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic