• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.sql.SQLException: No suitable driver

 
Raf Moerkens
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I always get this error message:

com.mysql.jdbc.Driver
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at db1.main(db1.java:30)
No suitable driver

Can someone help me and tell me why this db connection isn"t working?

Txs !


Here is the code :




//database package importeren
import java.sql.*;

public class db1 {


public static void main(String[] args) {
try{

Connection con = null;
Statement stmt = null;

//een driver laden
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
}
catch(ClassNotFoundException cl){
System.out.println(cl.getMessage());
}
catch(InstantiationException ins){
System.out.println(ins.getMessage());
}
catch(IllegalAccessException ill){
System.out.println(ill.getMessage());
}

String url = "jdbc:mysql://localhost/imc";

//een connectie aanmaken met de database
con = DriverManager.getConnection(url,"root","pasword");

//een statement aanmaken
stmt = con.createStatement();

//een ResultSet cre�ren
ResultSet rst = stmt.executeQuery("Select * from users");

while (rst.next()){
System.out.println(rst.getString("userID") + " " + rst.getString("name"));
}

}
catch(SQLException s){
System.out.println(s.getMessage());
s.printStackTrace();
}

}

}
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have your MySQL driver files in your classpath?
 
Raf Moerkens
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I added the following file to the classpath :

c:\mysql-connector-java-3.1.10\mysql-connector-java-3.1.10-bin.jar

I guess that's right.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds right I think. The two important bits are the Class.forName() line - which looks OK - and the jdbc url you use - which also looks OK. The documentation has a trouble-shooting section, if you are still having problems.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic