com.mysql.jdbc.CommunicationsException: Communications link failure due to und
lying exception:
** BEGIN NESTED EXCEPTION **
java.net.ConnectException
MESSAGE: Connection timed out: connect
STACKTRACE:
java.net.ConnectException: Connection timed out:
connect
at java.net.DualStackPlainSocketImpl.connect0
(Native Method)
at
java.net.DualStackPlainSocketImpl.socketConnect
(DualStackPlainSocke
mpl.java:69)
at java.net.AbstractPlainSocketImpl.doConnect
(AbstractPlainSocketImpl.
va:316)
at
java.net.AbstractPlainSocketImpl.connectToAddress
(AbstractPlainSock
Impl.java:177)
at java.net.AbstractPlainSocketImpl.connect
(AbstractPlainSocketImpl.ja
:164)
at java.net.PlainSocketImpl.connect
(PlainSocketImpl.java:154)
at java.net.SocksSocketImpl.connect
(SocksSocketImpl.java:390)
at java.net.Socket.connect(Socket.java:578)
at java.net.Socket.connect(Socket.java:527)
at java.net.Socket.<init>(Socket.java:424)
at java.net.Socket.<init>(Socket.java:240)
at
com.mysql.jdbc.StandardSocketFactory.connect
(StandardSocketFactory.
va:173)
at com.mysql.jdbc.MysqlIO.<init>
(MysqlIO.java:268)
at com.mysql.jdbc.Connection.createNewIO
(Connection.java:2745)
at com.mysql.jdbc.Connection.<init>
(Connection.java:1553)
at com.mysql.jdbc.NonRegisteringDriver.connect
(NonRegisteringDriver.ja
:285)
at java.sql.DriverManager.getConnection
(DriverManager.java:620)
at java.sql.DriverManager.getConnection
(DriverManager.java:200)
at Database.Connectivity.<init>
(Connectivity.java:48)
at Form.SignIn.<init>(SignIn.java:64)
at Form.SignIn$5.run(SignIn.java:389)
at java.awt.event.InvocationEvent.dispatch
(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEvent
(EventQueue.java:649)
at
java.awt.EventDispatchThread.pumpOneEventForFilters
(EventDispatchTh
ad.java:255)
at
java.awt.EventDispatchThread.pumpEventsForFilter
(EventDispatchThrea
java:170)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy
(EventDispatchTh
ad.java:160)
at java.awt.EventDispatchThread.pumpEvents
(EventDispatchThread.java:15
at java.awt.EventDispatchThread.pumpEvents
(EventDispatchThread.java:14
at java.awt.EventDispatchThread.run
(EventDispatchThread.java:136)
** END NESTED EXCEPTION **
Last packet sent to the server was 0 ms ago.
at com.mysql.jdbc.Connection.createNewIO
(Connection.java:2820)
at com.mysql.jdbc.Connection.<init>
(Connection.java:1553)
at com.mysql.jdbc.NonRegisteringDriver.connect
(NonRegisteringDriver.ja
:285)
at java.sql.DriverManager.getConnection
(DriverManager.java:620)
at java.sql.DriverManager.getConnection
(DriverManager.java:200)
at Database.Connectivity.<init>
(Connectivity.java:48)
at Form.SignIn.<init>(SignIn.java:64)
at Form.SignIn$5.run(SignIn.java:389)
at java.awt.event.InvocationEvent.dispatch
(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEvent
(EventQueue.java:649)
at
java.awt.EventDispatchThread.pumpOneEventForFilters
(EventDispatchTh
ad.java:255)
at
java.awt.EventDispatchThread.pumpEventsForFilter
( EventDispatchThrea
java:170)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy
(EventDispatchTh
ad.java:160)
at java.awt.EventDispatchThread.pumpEvents
(EventDispatchThread.java:15
at java.awt.EventDispatchThread.pumpEvents
(EventDispatchThread.java:14
at java.awt.EventDispatchThread.run
(EventDispatchThread.java:136)
答案 0 :(得分:1)
如果
,可能会发生这种情况检查您是否可以从正在执行此代码的服务器/计算机远程登录到mysql服务器的主机端口。如果主机和端口有效且连接正常,则telnet将显示空白屏幕。否则会显示类似
的内容连接到localhost ...无法在端口3306上打开与主机的连接:连接失败
答案 1 :(得分:1)
如果出现以下情况,则可能会发出包含ConnectionException
消息的"connection timed out"
。
连接失败还有其他原因,但它们会导致不同的异常或不同的消息。 (例如,您可以看到“连接被拒绝”,“未知主机”,“主机无法访问”,“网络无法访问”......)