数据库连接超时的问题

来源:互联网 发布:易语言源码大全 编辑:程序博客网 时间:2024/05/17 06:36
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was43810 seconds ago.The last packet sent successfully to the server was 43810 seconds ago, which  is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)        at java.lang.reflect.Constructor.newInstance(Unknown Source)        at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)        at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)        at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3246)        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1917)        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)        at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734)        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2019)        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1937)        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1922)        at com.mindpro.taxi.call.DBConnection.executeUpdate(DBConnection.java:64)        at com.mindpro.taxi.call.PassengerService$UdpServiceThread.updatePassenger(PassengerService.java:259)        at com.mindpro.taxi.call.PassengerService$UdpServiceThread.run(PassengerService.java:209)Caused by: java.net.SocketException: Software caused connection abort: socket write error        at java.net.SocketOutputStream.socketWrite0(Native Method)        at java.net.SocketOutputStream.socketWrite(Unknown Source)        at java.net.SocketOutputStream.write(Unknown Source)        at java.io.BufferedOutputStream.flushBuffer(Unknown Source)        at java.io.BufferedOutputStream.flush(Unknown Source)        at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3227)        ... 10 more


autoReconnect=true&failOverReadOnly=false 似乎不起作用

引用:http://blog.csdn.net/mqboss/article/details/6659001

1.按照错误的提示,可以在JDBC URL中使用autoReconnect属性,实际测试时使用了autoReconnect=true&failOverReadOnly=false,不过并未起作用,使用的是5.1版本,可能真像网上所说的只对4之前的版本有效。

2.没办法,只能修改MySQL的参数了,wait_timeout最大为31536000即1年,在my.cnf中加入:

[mysqld]

wait_timeout=31536000

interactive_timeout=31536000

重启生效,需要同时修改这两个参数。



原创粉丝点击