Ich bin ein neuer Programmierer mit BlueJ ich eine Klasse Connexion
, die eine Verbindung zu meiner MySQL-Datenbank namens erstellen hatte, aber ich bekomme diese Fehlermeldung:Wie beheben „java.lang.ClassNotFoundException: com.mysql.jdbc.Driver“ mit BlueJ und Wampserver
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Mein Code:
import java.sql.* ;
public class Connexion{
/**
* Connect to MySQL and read the table "Etat", then
* print the contents of the first column.
*/
public static void test()
{
try
{
// Load the database driver
Class.forName("com.mysql.jdbc.Driver") ;
// Get a connection to the database
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/OACA?user=root&password=") ;
// Print all warnings
for(SQLWarning warn = conn.getWarnings(); warn != null; warn = warn.getNextWarning())
{
System.out.println("SQL Warning:") ;
System.out.println("State : " + warn.getSQLState() ) ;
System.out.println("Message: " + warn.getMessage() ) ;
System.out.println("Error : " + warn.getErrorCode()) ;
}
// Get a statement from the connection
Statement stmt = conn.createStatement() ;
// Execute the query
ResultSet rs = stmt.executeQuery("SELECT * FROM Etat") ;
// Loop through the result set
while(rs.next())
System.out.println(rs.getString(1)) ;
// Close the result set, statement and the connection
rs.close() ;
stmt.close() ;
conn.close() ;
}
catch(SQLException se)
{
System.out.println("SQL Exception:") ;
// Loop through the SQL Exceptions
while(se != null)
{
System.out.println("State : " + se.getSQLState() ) ;
System.out.println("Message: " + se.getMessage() ) ;
System.out.println("Error : " + se.getErrorCode()) ;
se = se.getNextException() ;
}
}
catch(Exception e)
{
System.out.println(e) ;
}
}
public static void main(String[] args) {
test();
}
}
Wie kann ich eine Verbindung zu meiner MySQL v5.6.17-Datenbank herstellen, die sich in meinem Wampserver befindet? Ich denke, dass ich ein conector.jar brauche, aber ich weiß nicht, welches ich tatsächlich brauchen würde. Können Sie Ihre Meinung bitte geben?
Mögliche Duplizieren: http://stackoverflow.com/questions/17484764/java-lang-classnotfoundexception-com-mysql-jdbc-driver-in-eclipse –