JETTY部署注意的数据库连接问题

来源:互联网 发布:待办事项提醒软件 编辑:程序博客网 时间:2024/06/18 02:19

问题描述:

2012-05-25 09:34:22,712 WARN  [JDBCExceptionReporter.java:100] : SQL Error: 0, SQLState: 08S01

2012-05-25 09:34:22,714 ERROR [JDBCExceptionReporter.java:101] : The last packet successfully received from the server was65852 seconds ago.The last packet sent successfully to the server was 65852 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.

解决方案:

修改persistence.xml文件中相关的Hibernate属性

方法一:

<properties><property name="hibernate.dialect"  value="org.hibernate.dialect.MySQL5Dialect" /><property name="hibernate.connection.driver_class"value="com.mysql.jdbc.Driver" /><property name="hibernate.connection.url"value="jdbc:mysql://localhost:3306?characterEncoding=utf-8" /><property name="hibernate.connection.username" value="root" /><property name="hibernate.connection.password" value="123" /><property name="hibernate.cache.provider_class"value="org.hibernate.cache.NoCacheProvider" /><property name="hibernate.connection.url" value="jdbc:mysql://server/dbname?autoReconnect=true" /><property name="hibernate.show_sql" value="false" />  <!-- 自动检测空闲时间,MySQL默认的timeout时间为8小时,此处设定为每25200秒检测一次,下面的单位为秒 -->            <property name="connection.provider_class"                value="org.hibernate.connection.C3P0ConnectionProvider" />            <property name="hibernate.c3p0.acquire_increment" value="4" />            <property name="hibernate.c3p0.idle_test_period" value="3000" />            <property name="hibernate.c3p0.max_size" value="100" />            <property name="hibernate.c3p0.max_statements" value="15" />            <property name="hibernate.c3p0.min_size" value="5" />            <property name="hibernate.c3p0.timeout" value="25200" />            <property name="hibernate.c3p0.preferredTestQuery" value="select 1;" /></properties>



方法二:


<property name="hibernate.connection.url" value="jdbc:mysql://server/dbname?autoReconnect=true" /><property name="hibernate.connection.autoReconnect" value="true" /><property name="hibernate.connection.autoReconnectForPools" value="true" />

原创粉丝点击