File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Error: ClassNotFoundException: com.jdbc.mysql.jdbcDriver, Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Error: ClassNotFoundException: com.jdbc.mysql.jdbcDriver,"No suitable driver" " Watch "Error: ClassNotFoundException: com.jdbc.mysql.jdbcDriver,"No suitable driver" " New topic
Author

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

p Walsh
Greenhorn

Joined: Nov 13, 2003
Posts: 14
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

Joined: Mar 06, 2001
Posts: 13459

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

Joined: Nov 13, 2003
Posts: 14
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error: ClassNotFoundException: com.jdbc.mysql.jdbcDriver,"No suitable driver"