{MySQL} connexion via jdbc de java

Fermé
Espinosa - 17 oct. 2009 à 17:27
 espinosa - 17 oct. 2009 à 19:25
Bonjour,

je souhaite me connecter à une base de donnée sur internet avec mon logiciel en java (en cours de création)
seulement je rencontre des erreurs que je ne comprends pas suffisamment pour pouvoir les corriger.

compile-single:
Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:rmi://10.0.5.165:3306/jdbc:i6243719:bd
        at java.sql.DriverManager.getConnection(DriverManager.java:602)
        at java.sql.DriverManager.getConnection(DriverManager.java:185)
        at bdgl_projet.Main.main(Main.java:25)
Java Result: 1


voici la partie de mon code concerné :

String bdUrl = "jdbc:rmi://10.0.5.165:3306/jdbc:i6243719:bd";
        String user = "ZZZ";
        String mdp = "XXX";

        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection c = DriverManager.getConnection(bdUrl, user, mdp);
        Statement s = c.createStatement();

        // code SQL:
        ResultSet r =
                s.executeQuery(
                "SELECT id,nom " +
                "FROM Unite ");
    while(r.next()) {
      // minuscules et majuscules n'ont
      // aucune importance:
      System.out.println(
        r.getString("id") + ", " + r.getString("nom"));
        }
        s.close(); // fermer également ResultSet

    }
A voir également:

1 réponse

mon erreur a changé, voici mon nouveau code :

Class.forName("com.mysql.jdbc.Driver");
        
        String bdUrl = "jdbc:mysql://10.0.5.165:3306/jdbc:i6243719:bd";
        String user = "i6243719";
        String mdp = "ab3xx1hcauvc58e9";

        
        Connection c = DriverManager.getConnection(bdUrl, user, mdp);
        Statement s = c.createStatement();

        // code SQL:
        ResultSet r =
                s.executeQuery(
                "SELECT id,nom " +
                "FROM Unite ");
    while(r.next()) {
      // minuscules et majuscules n'ont
      // aucune importance:
      System.out.println(
        r.getString("id") + ", " + r.getString("nom"));
        }
        s.close(); // fermer également ResultSet

    }


et ma nouvelle erreur!

Exception in thread "main" com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:

** BEGIN NESTED EXCEPTION **

java.net.SocketException
MESSAGE: java.net.ConnectException: Connection timed out: connect

STACKTRACE:

java.net.SocketException: java.net.ConnectException: Connection timed out: connect
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:151)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:280)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1765)
at com.mysql.jdbc.Connection.<init>(Connection.java:430)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:268)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at bdgl_projet.Main.main(Main.java:28)


** END NESTED EXCEPTION **


at com.mysql.jdbc.Connection.createNewIO(Connection.java:1830)
at com.mysql.jdbc.Connection.<init>(Connection.java:430)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:268)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at bdgl_projet.Main.main(Main.java:28)
Java Result: 1
0