Win a copy of liveProject: Build an ML Recommender System this week in the Artificial Intelligence and Machine Learning forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

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.
 
Grow your own food... or this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic