Mysql avec eclipse

laurent2403 Messages postés 96 Statut Membre -  
 laurent2403 -
Bonjour,

voila je n'arrive pas a me connecter a ma base de donnée mysql , pour accéder a ma bd je passe par XAMP , j'ai mis le driver dans le java build path (mysql-connector-java-2.0.14-bin)
voici ma classe et merci beaucoup pour votre travail...


package base_de_donnees;

import java.sql.*;

public class Connection_Mysql {
public static void main(String[] args) {

String pilote = "com.mysql.jdbc.Driver";

try {
Class.forName(pilote);
System.out.println("driver etablie");
} catch (ClassNotFoundException e) {
System.out.println("driver not found");
e.printStackTrace();
}
try {

@SuppressWarnings("unused")
Connection connexion = DriverManager.getConnection(
"jdbc:mysql://localhost/test", "root", "pass");
System.out.println("connexion base mysql etablie");

} catch (SQLException e) {
System.out.println("pas de connexion");
e.printStackTrace();
}

}
}


voila ce me met la console:

Exception in thread "main" java.sql.SQLException: Communication failure during handshake. Is there a server running on localhost:3306?
at com.mysql.jdbc.MysqlIO.init(Unknown Source)
at com.mysql.jdbc.Connection.connectionInit(Unknown Source)
at com.mysql.jdbc.jdbc2.Connection.connectionInit(Unknown Source)
at com.mysql.jdbc.Driver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)

2 réponses

info_share Messages postés 2 Statut Membre
 
bonjour,

Tu devrais ajouter le jar de connection mysql au java build path, je pense c'est ça l'origine de l'erreur. Pour faire voici les étapes à suivre :
Bouton droit sur le projet, cliquer sur propriétés -->java build path --> librairies -->add external jars--> et choisis ton jar mysql.

J'espère ça résoud ton problème?
0
laurent2403
 
oui c'est bon merci j'ai change le jar ,j'ai pris la derniere version et ensuite, l'ai mis ou tu m'as dit ca marche merci de ton aide
0