天天看點

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 152,219,305 milliseconds ago.

資料庫伺服器:mysql5.0

應用伺服器:tomcat8.5

出現問題:

應用釋出後發現每過一段時間後tomcat就會報錯。錯誤資訊大概如下:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 152,219,305 milliseconds ago. The last packet sent successfully to the server was 152,219,305 milliseconds ago. 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.

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.

No operations allowed after connection closed.

java.sql.SQLException: Operation not allowed after ResultSet closed

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:988)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:974)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)

at com.mysql.jdbc.ResultSetImpl.checkClosed(ResultSetImpl.java:803)

at com.mysql.jdbc.ResultSetImpl.next(ResultSetImpl.java:6985)

at com.dz.servlet.LoginServlet.service(LoginServlet.java:54)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)

at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:845)

at org.apache.coyote.http11.Http11AprProtocol H t t p 11 C o n n e c t i o n H a n d l e r . p r o c e s s ( H t t p 11 A p r P r o t o c o l . j a v a : 688 ) a t o r g . a p a c h e . t o m c a t . u t i l . n e t . A p r E n d p o i n t Http11ConnectionHandler.process(Http11AprProtocol.java:688) at org.apache.tomcat.util.net.AprEndpoint Http11ConnectionHandler.process(Http11AprProtocol.java:688)atorg.apache.tomcat.util.net.AprEndpointWorker.run(AprEndpoint.java:1315)

at java.lang.Thread.run(Unknown Source)

在百度裡搜到很多,但是都沒有解決我的問題,今天看到了一篇寫的還算靠譜的文章,http://blog.csdn.net/liuqiyu/article/details/6092377推薦給大家

以下是我的mysql配置檔案my.ini的内容,加了最後一行配置

[mysqld]

port=3306

max_allowed_packet=200M

#Path to installation directory. All paths are usually resolved relative to this.

basedir=“C:/Program Files (x86)/MySQL/MySQL Server 5.0/”

#Path to the database root

datadir=“C:/Program Files (x86)/MySQL/MySQL Server 5.0/Data/”

default-character-set=gbk

default-storage-engine=INNODB

sql-mode=“STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION”

max_connections=1000

query_cache_size=0

table_cache=256

tmp_table_size=128M

thread_cache_size=8

myisam_max_sort_file_size=100G

myisam_max_extra_sort_file_size=100G

myisam_sort_buffer_size=8M

key_buffer_size=128M

read_buffer_size=4M

read_rnd_buffer_size=16M

sort_buffer_size=16M

innodb_additional_mem_pool_size=2M

innodb_flush_log_at_trx_commit=2

innodb_log_buffer_size=1M

innodb_buffer_pool_size=1G

innodb_log_file_size=10M

innodb_thread_concurrency=10

wait_timeout=1814400

上面是我貼出來的資料庫my.ini配置檔案的部分,把wait_timeout=1814400 配置在這裡就沒有問題了!!

繼續閱讀