Bonjour à tous,
J'essaie de me connecter à une base de données avec JDBC. Lorsque j'appelle registerDriver(new com.mysql.jdbc.Driver()) sur DriverManager, j'ai l'erreur suivant à la compilation: registerDriver(java.sql.Driver) in java.sql.DriverManager cannot be applied to (com.mysql.jdbc.Driver) DriverManager.registerDriver(new com.mysql.jdbc.Driver());. Voici le code incriminé:
Quelqu'un saurait-il d'où cela peut venir?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
60
61
62
63 package util.io; import java.awt.*; import java.awt.event.*; import java.sql.*; import java.sql.DriverManager; import java.sql.Connection; import java.sql.SQLException; import javax.swing.*; public class ConnexionBds { //----------------------------------------------------------------------- // Constructeur //----------------------------------------------------------------------- public ConnexionBds(String url, String user, String pwd) { check(); this.c = connect(url,user,pwd); System.out.println("connected"); } //----------------------------------------------------------------------- // méthodes //----------------------------------------------------------------------- //chargement du pilote private static void check() { try{ DriverManager.registerDriver(new com.mysql.jdbc.Driver()); } catch (ClassNotFoundException cnfe){ System.out.println("Le driver n'est pas trouvable!"); System.out.println("-------------------------------------------"); cnfe.printStackTrace(); System.exit(1); } } // Etablissement de la connexion private static Connection connect(String url, String user, String pwd){ Connection c = null; try{ c = DriverManager.getConnection(url,user,pwd); } catch (SQLException se){ System.out.println("Echec de connexion a la base de données"); se.printStackTrace(); System.exit(1); } return c; } public Connection getConnexionBds(){ return c; } //----------------------------------------------------------------------- // attributs privés //----------------------------------------------------------------------- private Connection c; }
Merci d'avance.
Partager