java.lang.ClassNotFoundException : com.mysql.jdbc.Driver
Bonjour,
J'ai l'erreur java.lang.ClassNotFoundException: com.mysql.jdbc.Driver qui s'affiche lorsque j'exécute mon application, j'ai vérifier toutes les solutions proposées pour ce genre d'erreur, mais en fait je viens de découvrir que le port 3306 est fermé est ce que ça pourrait être la cause de mon erreur.
Je travail avec netbeans, et j'ai déjà ajouter le "mysql-connector-java-5.1.7-bin" à mon projet en cliquant avec le bouton droit sur le répertoire "librairies" de mon projet et en sélectionnant "Add JAR".
Vous trouverez ci-dessous le code de ma connexion à la base de données:
Code:
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| private void connexionToCBTDB(){
Connection conn;
Statement stmt;
ResultSet rs;
String pilote="com.mysql.jdbc.Driver";
String url = new String("jdbc:mysql://localhost:3306/NetCad");
try
{
Class.forName(pilote);
conn = DriverManager.getConnection(url,"root","root");
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from enzyme");
while (rs.next())
{
String nom = rs.getString("eEC");
System.out.println(nom + "\n");
Font font = new Font(null,Font.PLAIN,12);
txta = new JTextArea("Résultat requête : " + nom);
ftxta = new JScrollPane(txta);
ftxta.setAutoscrolls(true);
txta.setLineWrap(true);
txta.setWrapStyleWord(true);
txta.setEditable(false);
txta.setFont(font);
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx=0;
gbc.gridy=5;
gbc.insets = new Insets(0,0,4,0);
gbc.anchor = GridBagConstraints.WEST;
getContentPane().add(txta, gbc);
}
rs.close();
stmt.close();
conn.close();
}
catch ( SQLException E)
{
System.err.println("SQLException: " + E.getMessage());
System.err.println("SQLState: " + E.getSQLState());
System.err.println("VendorError: " + E.getErrorCode());
JOptionPane.showMessageDialog(bd, "SQLException: " + E.getMessage() + "\n" + "SQLState: " + E.getSQLState() + "\n" + "VendorError: " + E.getErrorCode(),
"Problème lors de la connexion à la base",JOptionPane.ERROR_MESSAGE );
}
catch ( ClassNotFoundException E)
{
E.printStackTrace();
JOptionPane.showMessageDialog(bd, E.toString(),
"Problème lors de la connexion à la base",JOptionPane.ERROR_MESSAGE );
}
} |
Merci