Java MySQL JDBC通信链接失败

时间:2014-01-25 09:36:29

标签: java mysql jdbc

我有一个带有JDBC mysql连接的服务器,但每天早上我检查服务器时都会收到此错误:

  

java.sql.SQLException:通信链接失败:   java.io.EOFException,底层原因:null

     

**开始没有异常**

     

java.io.EOFException的

     

堆栈跟踪:

     

java.io.EOFException的           在com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1395)           在com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:1539)           在com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1930)           在com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1168)           在com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1279)           在com.mysql.jdbc.Connection.execSQL(Connection.java:2281)           在com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1634)           在hu.craftbox.Server.CraftboxServerHandler.messageReceived(CraftboxServerHandler.java:158)           在org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)           在org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)           在org.jboss.netty.channel.DefaultChannelPipeline $ DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)           在org.jboss.netty.handler.timeout.ReadTimeoutHandler.messageReceived(ReadTimeoutHandler.java:184)           在org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)           在org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)           在org.jboss.netty.channel.DefaultChannelPipeline $ DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)           在org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:296)           在org.jboss.netty.handler.codec.oneone.OneToOneDecoder.handleUpstream(OneToOneDecoder.java:70)           在org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)           在org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559)           在org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268)           在org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255)           在org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:88)           在org.jboss.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:108)           在org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:318)           在org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:89)           在org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178)           在org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)           在org.jboss.netty.util.internal.DeadLockProofWorker $ 1.run(DeadLockProofWorker.java:42)           在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)           at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:615)           在java.lang.Thread.run(Thread.java:744)

     

**结束了例外**

    at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:1714)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1930)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1168)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1279)
    at com.mysql.jdbc.Connection.execSQL(Connection.java:2281)
    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1634)
    at hu.craftbox.Server.CraftboxServerHandler.messageReceived(CraftboxServerHandler.java:158)
    at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
    at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
    at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
    at org.jboss.netty.handler.timeout.ReadTimeoutHandler.messageReceived(ReadTimeoutHandler.java:184)
    at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
    at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
    at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
    at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:296)
    at org.jboss.netty.handler.codec.oneone.OneToOneDecoder.handleUpstream(OneToOneDecoder.java:70)
    at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
    at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559)
    at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268)
    at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255)
    at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:88)
    at org.jboss.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:108)
    at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:318)
    at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:89)
    at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178)
    at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
    at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)

什么可能导致此问题,我该如何解决?

1 个答案:

答案 0 :(得分:1)

MySQL在一段时间后丢弃未使用的连接,因为它假定对方忘记关闭它。

您需要做的是根据您的业务正确配置MySQL, 检查here如何配置MySQL。