何时发生此异常?

时间:2011-06-11 06:20:29

标签: java jdbc

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)

2 个答案:

答案 0 :(得分:1)

如果

,可能会发生这种情况
  • MySQL服务器太忙或挂起
  • 无法访问网络
  • MySQL服务器未启动
  • 使用的连接参数无效。 (主机/端口)

检查您是否可以从正在执行此代码的服务器/计算机远程登录到mysql服务器的主机端口。如果主机和端口有效且连接正常,则telnet将显示空白屏幕。否则会显示类似

的内容
  

连接到localhost ...无法在端口3306上打开与主机的连接:连接失败

答案 1 :(得分:1)

如果出现以下情况,则可能会发出包含ConnectionException消息的"connection timed out"

  • MySQL服务是紧张性/挂起的,
  • MySQL服务正在运行,但太忙,无法接受新连接,
  • 防火墙是“黑洞”连接尝试,或
  • 网络硬件或路由问题是“黑洞”连接尝试。

连接失败还有其他原因,但它们会导致不同的异常或不同的消息。 (例如,您可以看到“连接被拒绝”,“未知主机”,“主机无法访问”,“网络无法访问”......)