[問題] Java連上MYSQL的問題

看板java作者 (學長姊好阿)時間15年前 (2008/09/28 18:32), 編輯推噓2(202)
留言4則, 3人參與, 最新討論串1/1
大家好,我用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
mysql 權限有沒有開?
09/28 18:36, 1F

09/28 18:40, , 2F
請問你是指從外部連結進去的root權限嗎?那個我有開
09/28 18:40, 2F

09/28 19:18, , 3F
之前弄mysql是裝php的 這個會不會有關係?
09/28 19:18, 3F

10/07 19:53, , 4F
PORT 有衝突嗎 我之前也是PHP佔用 或許有關西
10/07 19:53, 4F
文章代碼(AID): #18trrN1b (java)