The last packet successfully received from the server was 2,926,157 milliseconds ago. The last packe

 

Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 2,926,157 milliseconds ago. The last packet sent successfully to the server was 2,926,158 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.mysql

解決辦法:
若是鏈接閒置8小時 (8小時內沒有進行數據庫操做), mysql就會自動斷開鏈接, 要重啓tomcat.
不用hibernate的話, connection url加參數: autoReconnect=true
用hibernate的話, 加以下屬性: sql

<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider
        </property>
        <property name="hibernate.c3p0.max_size">50</property>
        <property name="hibernate.c3p0.min_size">5</property>
        <property name="hibernate.c3p0.timeout">10</property>
        <property name="hibernate.c3p0.max_statements">50</property>
        <property name="hibernate.c3p0.idle_test_period">10</property>
        <property name="hibernate.c3p0.acquire_increment">2</property>數據庫

相關文章
相關標籤/搜索