作者kiwi0801 (學長姊好阿)
站內java
標題[問題] Java連上MYSQL的問題
時間Sun Sep 28 18:32:53 2008
大家好,我用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)
推 PsMonkey:mysql 權限有沒有開? 09/28 18:36
→ kiwi0801:請問你是指從外部連結進去的root權限嗎?那個我有開 09/28 18:40
→ kiwi0801:之前弄mysql是裝php的 這個會不會有關係? 09/28 19:18
推 marnith:PORT 有衝突嗎 我之前也是PHP佔用 或許有關西 10/07 19:53