Bonjour à vous..
j'ai installé mysql-server sous ubuntu jeos (qui est installé sous une machine virtuel) et j'utilise myeclipse qui se trouve sous windows,je veux me connecter sur la base de donnée mysql en utilisant le langage java sous myeclipse..
voici le code que j'utilise mais il me retourne une erreur!!
si j'utilise la base de données mysql qui se trouve sous la même machine c'est à dire sous windows il se fonctionne très bien mais à distance non
pouvez vous m'aider!!
a propos j'ai déjà donné tous les privilèges à root.
et voila l'erreur:
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 import java.sql.*; import java.awt.*; import javax.swing.*; public class connect{ public static void main(String[] args) { try { Class.forName("com.mysql.jdbc.Driver"); String url = "jdbc:mysql://192.168.0.2:3306/essai"; String user = "root"; String passwd = "mouna"; Connection conn = DriverManager.getConnection(url, user, passwd); //Création d'un objet Statement Statement state = conn.createStatement(); //L'objet ResultSet contient le résultat de la requête SQL ResultSet result = state.executeQuery("SELECT * FROM etudiant"); //On récupère les MetaData ResultSetMetaData resultMeta = result.getMetaData(); System.out.println("\n**********************************"); //On affiche le nom des colonnes for(int i = 1; i <= resultMeta.getColumnCount(); i++) System.out.print("\t" + resultMeta.getColumnName(i).toUpperCase() + "\t *"); System.out.println("\n**********************************"); while(result.next()){ for(int i = 1; i <= resultMeta.getColumnCount(); i++) System.out.print("\t" + result.getObject(i).toString() + "\t |"); System.out.println("\n---------------------------------"); } result.close(); state.close(); } catch (Exception e) { e.printStackTrace(); } } }
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 java.sql.SQLException: Access denied for user 'root'@'192.168.0.1' (using password: YES) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3562) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3494) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:920) at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4000) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1285) at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2186) at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:787) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:353) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at connect.main(connect.java:15)
Partager