Mysql不能连接

com.mysql.jdbc.CommunicationsException: Communications link failure due to under
lying exception:

** BEGIN NESTED EXCEPTION **

java.io.EOFException

STACKTRACE:

java.io.EOFException
        at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1913)
        at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2304)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2803)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:3170)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:3099)
        at com.mysql.jdbc.Statement.executeQuery(Statement.java:1169)
        at com.xuchenguang.Dbrw.EQ(Dbrw.java:46)
        at com.xuchenguang.SMRev.run(SmsModemRev.java:34)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExec
utor.java:650)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:675)
        at java.lang.Thread.run(Thread.java:595)


** END NESTED EXCEPTION **



Last packet sent to the server was 0 ms ago.
第719行:java.lang.NullPointerException
SMRev线程发现异常,丢弃!
2010-01-16 09:05:12 -DB- > 删除一个无效链接.
2010-01-16 09:05:12 -DB- > 创建一个新的链接.



http://www.wangzhongyuan.com/archives/610.html



问题分析:这个错误是Java程序没有连接上Mysql,或者链接超时导致无法进行任何与数据库相关的操作。这个错误的本质是一个网络的问题。

问题解决:首先,需要分别排查以下情况:
(1)MySql服务器是否支持TCP/IP连接;
(2)服务器端以及运行Java程序的客户端是否启用了防火墙,端口是否被占用;
(3)JDBC的驱动是否正确合适;
(4)是否启用了IPv6?如果现在使用的IPv6,那么换成IPv4再试试看;

如果上述情况都排除之后,还是出现如上的异常错误,那么很有可能是你电脑所处的网络存在问题,你可以尝试一下换个地方上网运行这个包含JDBC的Java程序,或者换个时间再次运行。

参考如下:

http://andyao.iteye.com/blog/38506

查看了Mysql的文档,以及Connector/J的文档以及在线说明发现,出现这种异常的原因是:

Mysql服务器默认的“wait_timeout”是8小时,也就是说一个connection空闲超过8个小时,Mysql将自动断开该connection。这就是问题的所在,在C3P0 pools中的connections如果空闲超过8小时,Mysql将其断开,而C3P0并不知道该connection已经失效,如果这时有Client请求connection,C3P0将该失效的Connection提供给Client,将会造成上面的异常。

参考二:

http://forums.sun.com/thread.jspa?threadID=5263225



That error simply means that the database cannot be reached.

As mentioned before, the URL and/or port number can be wrong, there can be a firewall which blocks the port, or the database is simply down or does not accept TCP/IP connections.

Which operating system exactly are you using? Which database implementation and version exactly are you using? Which JDBC driver implementation and version exactly are you using?

你可能感兴趣的:(java,thread,mysql,jdbc,防火墙)