資料庫連接逾時的問題

來源:互聯網
上載者:User
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

重啟生效,需要同時修改這兩個參數。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.