Bonjour,
J'ai un probléme qui je pense est lié à l'importation du driver mysql sous My eclipse.
(Je travail sous une plateforme Tomcat et je code sur Myeclipse).
Voici le code que j'utilise pour me connecter à ma base de données:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| try {
Statement stmt;
Class.forName("com.mysql.jdbc.Driver");
System.out.println("driver chargé");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "ouvrir");
System.out.println("connexion ouverte");
stmt=conn.createStatement();
String s2="insert into u1.personne values('moiiiiiii','valjean',123,'1988-05-22')";
int n=stmt.executeUpdate(s2);
System.out.println(n+"enregistrements ajoutés");
stmt.close();
conn.close();
}
catch(ClassNotFoundException e){
e.printStackTrace();
}
catch(SQLException e){
while (e!=null) {
System.out.println(e.getMessage());
System.out.println("ANSI-92 SQL State:"+e.getSQLState());
System.out.println("Vendor error:"+e.getErrorCode());
e=e.getNextException();
}
} |
Voici le résultat retourné:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Pourtant j'ai bien ajouté le connecteur/j mysql (.jar) dans myeclipse avec la manipulation suivante:
clique droit sur le projet/ properties puis java Built Path / Libraries/ Add external Jars
Que faut-il que je fasse d'autre?
Merci pour vos réponses.
Partager