如何連接與我的數據庫交互的java?我正在使用XAMPP for mysql 而且我知道我使用的端口有問題..我只是複製了其他端口正在使用的互聯網但我真的不知道我的數據庫端口號是什麼 我要檢查數據庫的端口嗎? //localhost:3306
如何使用java連接到數據庫
這裏是我的代碼:
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.print("COnnection succesfull");
}
catch(Exception ex)
{
System.out.print("Unable to connect ");
}
try
{
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/test?user=root&password=";
Connection con = DriverManager.getConnection(url);
System.out.print("Connection Stablished");
}
catch(Exception ex)
{
System.out.print("Connect cannot stablished");
}
我還是不能連接 – 2013-04-26 01:54:40
這個例外說了些什麼? – cakil 2013-04-26 01:59:11
stablishedjava.lang.ClassNotFoundException:com.mysql.jdbc.Driver – 2013-04-26 02:07:04