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();
}
}
}