Bonjour voilà je suis en train d'essayer de me connecter à une base MySQL dans un programme java mais j'ai une erreur qui apparait.
Je suis sous Mac OS X et j'utilise MAMP pour la base de données.
Voici mon code (j'ai aussi testé avec un RowSet cela fait pareil)Erreur SQL : 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.
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 import java.sql.*; public class Main { public static void main(String[] args) { try{ Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection cx = DriverManager.getConnection("jdbc:mysql://localhost/mabase","login","mdp"); Statement st = cx.createStatement(); String req = "select * from etudiant"; ResultSet rs = st.executeQuery(req); while(rs.next()){ System.out.println(rs.getString("nom")); } cx.close(); }catch(ClassNotFoundException e){ System.out.println("Erreur de classe : "+e.getMessage()); }catch(SQLException e){ System.out.println("Erreur SQL : "+e.getMessage()); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } }
Partager