wie installieren Sie den JDBC-und wie es zu benutzen, um die mysql-Verbindung?

bin ich versucht zu installieren, JDBC, aber ich weiß nicht wie, wenn Sie nur die jar-Datei kopiert habe ich es, um meine java-ext-Ordner, aber es immer wieder geben mir eine Fehlermeldung, kann jemand mir zeigen, wie Sie komplett den Treiber installieren und es benutzen?

unten die codes, die ich verwendet

import java.sql.*;
   public class Test1
   {
       public static void main (String[] args)
       {
String url = "jdbc:mysql://localhost:3306/sabayafr_sabmah";
String username = "root";
String password = "ma";
Connection connection = null;
try {
    System.out.println("Connecting database...");
    connection = DriverManager.getConnection(url, username, password);
    System.out.println("Database connected!");
} catch (SQLException e) {
    System.err.println("Cannot connect the database!");
    e.printStackTrace();
} finally {
    System.out.println("Closing the connection.");
    if (connection != null) try { connection.close(); } catch (SQLException ignore) {}
}

       }
   }

Und unten ist die Antwort, die ich bekommen

Cannot connect to database server

Update # 3

C:\Users\AlAsad\Desktop>java -cp .;mysql-connector-java-5.0.8-bin.jar Test1
Connecting database...
Cannot connect the database!
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/
sabayafr_sabmah
        at java.sql.DriverManager.getConnection(Unknown Source)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at Test1.main(Test1.java:12)
Closing the connection.
Als BalusC erwähnt: bitte ersetzen Sie System.err.println ("Cannot connect to database server"); mit e.printStackTrace() und post die Ausnahme.

InformationsquelleAutor Mahmoud | 2010-07-05

Schreibe einen Kommentar