• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java.sql.SQLException: No suitable driver

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();
}

}

}
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic