亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

用JDBC和MySQL解決“通信鏈路故障”

用JDBC和MySQL解決“通信鏈路故障”

慕哥9229398 2019-05-31 16:51:37
用JDBC和MySQL解決“通信鏈路故障”我試圖連接到本地MySQL服務器,但是我一直收到一個錯誤。這是密碼。public class Connect {     public static void main(String[] args) {         Connection conn = null;         try {             String userName = "myUsername";             String password = "myPassword";             String url = "jdbc:mysql://localhost:3306/myDatabaseName";             Class.forName("com.mysql.jdbc.Driver").newInstance();             conn = DriverManager.getConnection(url, userName, password);             System.out.println("Database connection established");         } catch (Exception e) {             System.err.println("Cannot connect to database server");             System.err.println(e.getMessage());             e.printStackTrace();         } finally {             if (conn != null) {                 try {                     conn.close();                     System.out.println("Database Connection Terminated");                 } catch (Exception e) {}             }         }     }}還有錯誤:Cannot connect to database serverCommunications link failureThe last packet sent successfully to the server was 0  milliseconds ago.  The driver has not received any packets from the server.com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications  link  failureThe last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets   from the server.         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)         at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)         at java.lang.reflect.Constructor.newInstance(Constructor.java:513)         at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)我已經設置了類路徑,確保我的.cnf將跳轉網絡選項注釋掉。Java版本為1.2.0_26(64位)MySQL 5.5.14 MySQL連接器5.1.17我確保用戶能夠訪問我的數據庫。
查看完整描述

3 回答

?
慕碼人8056858

TA貢獻1803條經驗 獲得超6個贊

如果你正在使用MamPpro,簡單的修復,我真的希望我已經意識到之前,我開始搜索互聯網數天試圖找出這一點。真的這么簡單.。

您只需單擊MamPMySQL選項卡中的“允許網絡訪問MySQL”即可。

真的,就是這樣。

哦,您可能仍然需要將綁定地址更改為0.0.0.0或127.0.0.1,就像上面的文章所概述的那樣,但是如果您是MamP用戶,單擊該框可能會解決您的問題。


查看完整回答
反對 回復 2019-05-31
?
料青山看我應如是

TA貢獻1772條經驗 獲得超8個贊

設置bind-address到服務器的網絡IP上,而不是本地主機默認設置,并對我的用戶設置特權為我工作。

我的.cnf:

bind-address = 192.168.123.456

MySQL控制臺:

GRANT ALL PRIVILEGES ON dbname.* to username@'%' IDENTIFIED BY 'password';


查看完整回答
反對 回復 2019-05-31
  • 3 回答
  • 0 關注
  • 2197 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號