[問題] Java連上MYSQL的問題
大家好,我用Connector/J連上mysql
一開始先測試有抓到com.mysql.jdbc.Driver
但是當我要連線到mysql的時候
用網路上看到的方法
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/bulletin";
String user = "xxxx";
String password = "xxxx";
try {
Class.forName(driver);
Connection conn =
DriverManager.getConnection(url,
user, password);
if(conn != null && !conn.isClosed()) {
System.out.println("資料庫連線測試成功!");
conn.close();
}
}
catch(ClassNotFoundException e) {
System.out.println("找不到驅動程式類別");
e.printStackTrace();
}
catch(SQLException e) {
e.printStackTrace();
}
會顯示下列錯誤訊息
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link
failure
Last packet sent to the server was 0 ms ago.
看起來像是連結逾時
不過找不到問題所在
請問大家我只有裝java sdk跟mysql的jar檔
會是這個問題嗎?
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.252.127.4
※ 編輯: kiwi0801 來自: 123.252.127.4 (09/28 18:33)
推
09/28 18:36, , 1F
09/28 18:36, 1F
→
09/28 18:40, , 2F
09/28 18:40, 2F
→
09/28 19:18, , 3F
09/28 19:18, 3F
推
10/07 19:53, , 4F
10/07 19:53, 4F