Hibernate连接数据库超时设置autoReconnect=true(Mysql)
来源:互联网 发布:网络诈骗的表现形式有 编辑:程序博客网 时间:2024/05/18 12:30
错误信息
ERROR org.hibernate.transaction.JDBCTransaction - JDBC begin failed
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was36313 milliseconds ago.The last packet sent successfully to the server was 36313 milliseconds 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.
原因:如果连接闲置8小时 (8小时内没有进行数据库操作), mysql就会自动断开连接, 要重启tomcat;
或配置hibernate自动重连'autoReconnect=true'
解决方法:下面是我的配置(mysql数据库,spring+hiberante)
applicationContext.xml
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost/db?autoReconnect=true&autoReconnectForPools=true"/>
<property name="username" value="root"/>
<property name="password" value="123"/>
<property name="validationQuery" value="SELECT 1"/>
<property name="testOnBorrow" value="true"/>
</bean>
- Hibernate连接数据库超时设置autoReconnect=true(Mysql)
- 使用Hibernate + MYSQL数据库问题(Hibernate连接数据库超时设置autoReconnect=true)
- Hibernate连接数据库超时设置autoReconnect=true
- Hibernate连接数据库超时设置autoReconnect=true
- Hibernate连接数据库超时设置autoReconnect=true
- Hibernate连接数据库超时设置autoReconnect=true
- Mysql 连接数据库超时设置autoReconnect=true
- 连接数据库超时设置autoReconnect=true
- 连接数据库超时设置autoReconnect=true
- 连接数据库超时设置autoReconnect=true
- 连接数据库超时设置autoReconnect=true
- Mysql 设置超时重连 autoReconnect=true
- 连接数据库超时设置autoReconnect=true(mysql5以上的,设置autoReconnect=true 是无效的 只有4.x版本,起作用)
- mysql超时设置的问题 using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
- 连接数据库地址后面加上?autoReconnect=true&useUnicode=true&characterEncoding=utf8 日志
- Hibernate连接数据库超时设置
- 数据库 mysql jdbcURL的autoReconnect
- Hibernate+MySQL连接超时解决办法
- JavaScript、jQuery、Ajax以及json间的关系
- 新线智能云平台体验版正式发布
- RMAN Crosscheck 和 Delete 命令的2个实例
- Youtube原理
- 回归了 ~
- Hibernate连接数据库超时设置autoReconnect=true(Mysql)
- 如何 搭建 RMAN 备份平台
- ESI 动态缓存技术(转载)
- 解决android http请求带中文参数会乱码(url编码)
- C#输入全角转半角以及格式检查
- jQuery中的事件处理
- 关于adbd进程的ROOT权限问题
- jQuery实现Ajax
- 浅谈Hibernate的flush机制