com.mysql.jdbc.CommunicationsException: Communications link failure
com.mysql.jdbc.CommunicationsException: Communications link failure
Last packet sent to the server was 0 ms ago.
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1070)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2104)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:729)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:298)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:283)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at pack.java.connection.mysql.Connection.createConn(Connection.java:11)
at pack.java.connection.mysql.Connection.main(Connection.java:21)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:367)
at java.net.Socket.connect(Socket.java:524)
at java.net.Socket.connect(Socket.java:474)
at java.net.Socket.<init>(Socket.java:371)
at java.net.Socket.<init>(Socket.java:213)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:256)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:276)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2027)
... 7 more
null
解決方案:
public static java.sql.Connection createConn() {
java.sql.Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3036/portal","root","password");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
檢查你的埠號. 是否寫錯..是3306不是3036. 寫錯了,.就會發生如上錯誤!.
mysql預設埠3306,如果沒有改變..不需要指定也行。
相關文章
- mysql 報錯 Communications link failureMySqlAI
- 經常報錯:Communications link failureAI
- 應用端連線MySQL資料庫報Communications link failureMySql資料庫AI
- 解決Java程式連線mysql資料庫出現CommunicationsException: Communications link failure錯誤的問題JavaMySql資料庫ExceptionAI
- 【Azure 應用服務】App Service 無法連線到Azure MySQL服務,報錯:com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failureAPPMySqlJDBCExceptionAI
- 練習使用list failure,advise failure; repair failure;AI
- Failure is not fatal, but failure to change might be.AI
- E. Disrupting Communications
- design for failureAI
- DCN-Digital Communications and NetworksGit
- Assertion failure 錯誤AI
- Ext success failure 呼叫AI
- Office Communications Server 2007Server
- DRIVER_POWER_STATE_FAILUREAI
- Vagrant:NS_ERROR_FAILUREErrorAI
- Assertion failure in -[UICollectionViewData validateLayoutInRect:]AIUIView
- Error: Debug Failure at typeToStringErrorAI
- Preferred Read Failure GroupsAI
- [Linux] kernel: page allocation failureLinuxAI
- [virtualbox] temporary failure in name resolutionAI
- ORA-29516: Aurora assertion failure: Assertion failure at joez.c:3311AI
- 關於Java communications API的問題,請教高手JavaAPI
- database link概述Database
- CREATE DATABASE LINKDatabase
- Database Link使用Database
- 建立Database LinkDatabase
- oracle database linkOracleDatabase
- Management on database linkDatabase
- oracle article linkOracle
- ASM Failure Group的一點理解ASMAI
- datafilecopy header validation failure problemHeaderAI
- Failure at scls_scr_create with code 1AI
- Oracle ASM (10) - ASM中優先讀failure group配置ASM_PREFERRED_READ_FAILURE_GROUPSOracleASMAI
- Oracle ASM (11) - ASM中優先讀failure group配置ASM_PREFERRED_READ_FAILURE_GROUPSOracleASMAI
- MSN異常,“msn windows live communications platform 已停止工作”WindowsPlatform
- Fumi Communications:日本85%的高中妹紙愛用iPhoneiPhone
- npm link 命令解析NPM
- Database Link的建立Database