Exception com.mysql.jdbc.CommunicationsException in development

Source: Internet
Author: User

Exceptions encountered by Web development:

Com.mysql.jdbc.CommunicationsException:The last packet successfully received from the server was58129 seconds ago. Thelast Packet sent successfully to the server was 58129 seconds ago, which islonger than the server configured value of ' Wait_timeout '. Should considereither expiring and/or testing connection validity before use in yourapplication, increasing the server Configured values for client timeouts, orusing the Connector/j Connection property ' Autoreconnect=true ' to avoid thisprob Lem.


Workaround:

If the connection is idle for 8 hours ( No database operation within 8 hours ), MySQL will automatically disconnect and restart Tomcat.

without hibernate , connection URL plus parameter : autoreconnect=true


with hibernate , Add the following attributes :  

<propertyname= "Connection.autoreconnect" >true</property>

<propertyname= "Connection.autoreconnectforpools" >true</property>

<propertyname= "Connection.is-connection-validation-required" >true</property>

If you also use the c3p0 connection pool :

<propertyname= "Hibernate.c3p0.acquire_increment" >1</property>

<propertyname= "Hibernate.c3p0.idle_test_period" >0</property>

<propertyname= "Hibernate.c3p0.timeout" >0</property>

<propertyname= "Hibernate.c3p0.validate" >true</property>


or the most benevolent solution, is to directly modify the MySQL configuration file My.ini in the configuration file after the last increase wait_timeout=343232 The number is in seconds. it 's more convenient to change it by ten years.


Exception com.mysql.jdbc.CommunicationsException in development

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.