package javaapplication1;
import java.sql.*;
public class JavaApplication1{
public static void main(String[] args) {
System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/TEST/ANKUR1";
String dbName = "jdbctutorial";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "root";
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection("TEST1/ANKUR","root","school");
System.out.println("Connected to the database");
conn.close();
System.out.println("Disconnected from database");
} catch (Exception e) {
System.out.println(e);
}
}
}
我已經安裝了MySQL 5.5我的機器上,我在所需的文件夾複製Java的connector.jar文件。我的數據庫是test1,表是ankur。請參閱我正在使用此代碼來檢查與NetBeans 7的連接。是否有任何建議?錯誤代碼:java.sql.SQLException中:發現測試沒有合適的驅動程序/ ANKUR
我知道有一些問題,但我想知道爲什麼會出現此錯誤? –
您是否在項目中添加了mysql jar參考? –