0

I am trying to connect to mysql in java (I use Wamp) so I used the following code : (I'm using Eclipse)

package genererPlanning;
import java.sql.*;

public class genererPlanning{
    static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
    static final String DB_URL = "jdbc:mysql://localhost/mysql";

    static final String USER = "root";
    static final String PASS = "";

    public static void main(String[] args){
        Connection conn = null;
        try {
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root", "");
        }
        catch (SQLException ex){
            System.out.println("SQLException: " + ex.getMessage());
            System.out.println("SQLState: " + ex.getSQLState());
            System.out.println("VendorError: " + ex.getErrorCode());
        }
    }
}

But it returned me this text :

SQLException: No suitable driver found for jdbc:mysql://localhost:3306/mysql
SQLState: 08001
VendorError: 0

Do you know why it does not work?
PS : I looked at theses links but don't find my answer :
- stackoverflow
- stackoverflow
- stackoverflow
- commentcamarche

Thanks for all.

Community
  • 1
  • 1
Antoine Duval
  • 342
  • 3
  • 20
  • 1
    Do you have the mysql driver lib (jar file) in your build path? – aw-think May 27 '15 at 10:38
  • 1
    You miss the `mysql-connector.jar` in your classpazth – Jens May 27 '15 at 10:38
  • Indeed, this was not mentioned in the tutorial. Can you tell me where to find ( and add) this .jar please ? – Antoine Duval May 27 '15 at 10:41
  • All the linked questions answer the question - apparently you can't recognize it as an answer. Do you know how to work with jar libraries and/or the Java classpath? – Gimby May 27 '15 at 11:25

2 Answers2

1

You need mysql jdbc connector..download from this site

Ragu
  • 373
  • 5
  • 15
1

You need to use the mysql-connector.jar

Here's the link with instructions as to how to set it to your classpath.

http://code.google.com/p/find-ur-pal/downloads/detail?name=mysql-connector-java-5.1.18-bin.jar&

Meghdeep Ray
  • 5,262
  • 4
  • 34
  • 58