Bonjour,

Je n'ai jamais utilisé MySQL auparavant. Après quelques soucis lors de l'installation de MySQL Server, j'ai finalement tout installé. Mais depuis quelques jours et malgré plusieurs tentatives je n'arrive pas à connecter mon code Java qui est rédigé sur Netbeans, à MySQL. J'ai bien ajouté les librairies (MySQL-connector et MySQL JDBC Driver).

Le but de mon projet est de créer une application (pour une entreprise donc je resterai vague sur les détails ...) qui permettrait à partir d'un fichier XML contenant des données, d'extraire et de stocker ces données dans une table MySQL, de les afficher sur une interface graphique (d'ou le recours à Netbeans) et ensuite de générer un message en HL7 (car ce sont des données d'ordre médical) vers un appareil médical qui renverra ensuite un message HL7 avec les résultats.

Voici mon code pour tenter de me connecter à ma BDD : (avec mdp qui est le mot de passe que j'ai rentré en installant mySQL, et remplissage_table le nom de ma base de données au format sql)

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
package testbdd;
 
import java.sql.*;
import java.sql.DriverManager;
import java.sql.ResultSet;
/**
 *
 * @author Enora
 */
public class TestBDD {
 
     /**
      * @param args the command line arguments
      */
     public static void main(String[] args) {
          // TODO code application logic here 
 
Connection connexion = null;
try {
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Le pilote JDBC MySQL a été chargé");
connexion = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/Remplissage_table", "root","mdp");
System.out.println("Connexion à la BDD OK");
Statement state = connexion.createStatement();
ResultSet result = state.executeQuery("SELECT * FROM Demandes_exam");
ResultSetMetaData resultMeta = result.getMetaData();
for(int i = 1; i <= resultMeta.getColumnCount(); i++)
System.out.print(resultMeta.getColumnName(i).toUpperCase() + " | ");
System.out.println();
while(result.next()){
for(int i = 1; i <= resultMeta.getColumnCount(); i++)
System.out.print(result.getObject(i).toString() + " | ");
System.out.println();
}
result.close();
state.close();
connexion.close();
} catch (Exception e) {
e.printStackTrace();
}
     }
 
}
La grande partie de ce code provient d'un autre forum sur internet dont je me suis inspirée.
Je précise également que le base de données utilisée se situe dans un dossier sur le bureau,et non pas dans un des fichiers de l'application mysql

Et voici le message d'erreur renvoyé :
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
Le pilote JDBC MySQL a été chargé
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
 
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
	at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1117)
	at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:355)
	at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2461)
	at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2498)
	at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2283)
	at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:822)
	at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
	at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:404)
	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:317)
	at java.sql.DriverManager.getConnection(DriverManager.java:664)
	at java.sql.DriverManager.getConnection(DriverManager.java:247)
	at testbdd.TestBDD.main(TestBDD.java:27)
Caused by: java.net.ConnectException: Connection refused: connect
	at java.net.DualStackPlainSocketImpl.connect0(Native Method)
	at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
	at java.net.Socket.connect(Socket.java:589)
	at java.net.Socket.connect(Socket.java:538)
	at java.net.Socket.<init>(Socket.java:434)
	at java.net.Socket.<init>(Socket.java:244)
	at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:259)
	at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:305)
	... 15 more
J'espère que l'un d'entre vous pourra m'aider car je commence à désespérer après toutes mes tentatives

Je précise aussi que le ligne qui ne marche pas est celle-ci : connexion = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/Remplissage_table", "root","mdp"); La suite du programme ne m'interesse pas vraiment puisque je vais la modifier ensuite.


Un grand merci d'avance