解决 Communications link failure due to underlying exception

木来 木来

今天在连接数据库库的时候出现了一下错误

com.mysql.jdbc.CommunicationsException: 
Communications link failure due to underlying exception: 
** BEGIN NESTED EXCEPTION ** 
com.mysql.jdbc.exceptions.
MySQLNonTransientConnectionException MESSAGE: 
Communication link failure, message from server: 
"Can't get hostname for your address" STACKTRACE: 
com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException:
 Communication link failure, message from server: 
"Can't get hostname for your address" 
at com.mysql.jdbc.SQLError.
createSQLException(SQLError.java:921)at 
com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1070) 
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2775) 
at com.mysql.jdbc.Connection.<init>(Connection.java:1555) 
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
 at java.sql.DriverManager.getConnection(Unknown Source)
 at java.sql.DriverManager.getConnection(Unknown Source) 
at dbhelper.DBHelper.getConnection(DBHelper.java:26) 
at dbhelper.DBHelper.main(DBHelper.java:34) 
** END NESTED EXCEPTION ** 
Last packet sent to the server was 0 ms ago. 
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2847) 
at com.mysql.jdbc.Connection.<init>(Connection.java:1555) 
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285) 
at java.sql.DriverManager.getConnection(Unknown Source) 
at java.sql.DriverManager.getConnection(Unknown Source) 
at dbhelper.DBHelper.getConnection(DBHelper.java:26) 
at dbhelper.DBHelper.main(DBHelper.java:34)

解决 :

打开服务列表 Ctrl+shift+Esc 打开服务

查看mysql登录为 是否为网络服务,右键属性,修改为本地服务——>成功

0 条评论