在那裏我用下面的代碼腳麻可能有人向我解釋:JBDC和phpMyAdmin的/ MySQL的不連接
package newdbtet;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
public class NewDBTet {
public static void main(String[] args) throws InstantiationException, SQLException, IllegalAccessException {
try {
System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "evidence_db";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "";
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url + dbName, userName, password);
System.out.println("Connected to the database");
conn.close();
} catch (ClassNotFoundException ex) {
Logger.getLogger(NewDBTet.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
異常錯誤:
Jul 16, 2012 2:59:24 PM newdbtet.NewDBTet main
SEVERE: null
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
這是否意味着我的天堂」正確安裝驅動程序/庫?對不起 - 不是Java的最佳選擇。
你預計會發生什麼? – jn1kk 2012-07-16 13:46:47
在catch塊中打印異常。可能有一些例外。 – kosa 2012-07-16 13:46:56