本文最后更新于:4 个月前

org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 2,431 milliseconds ago.  The last packet sent successfully to the server was 2,417 milliseconds ago.
### The error may exist in com/melodyhub/mapper/UserMapper.xml
### The error may involve com.melodyhub.mapper.UserMapper.selectUser
### The error occurred while executing a query
### Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 2,431 milliseconds ago.  The last packet sent successfully to the server was 2,417 milliseconds ago.

	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:149)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)

解决:
mysql超时设置的问题
如果连接闲置8小时 (8小时内没有进行数据库操作), mysql就会自动断开连接。

connection url中加参数: autoReconnect=true

jdbc.url=jdbc:mysql://localhost:3306/database?autoReconnect=true&autoReconnectForPools=true

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!

[转]Spring IoC有什么好处呢? 上一篇
SpringMVC:回顾MVC 下一篇

 目录