org.springframework.dao.DataAccessResourceFailureException: SqlMapClient operation; SQL [];
--- The error occurred while applying a parameter map.
--- Check the DyDaoImpl_getdaoqilist-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.io.EOFException
STACKTRACE:
java.io.EOFException
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1913)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2304)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2803)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1169)
at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:693)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:794)
at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:168)
at sun.reflect.GeneratedMethodAccessor98.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.ibatis.common.jdbc.logging.PreparedStatementLogProxy.invoke(PreparedStatementLogProxy.java:62)
at com.sun.proxy.$Proxy24.execute(Unknown Source)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:185)
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.sqlExecuteQuery(MappedStatement.java:221)
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:189)
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryForList(MappedStatement.java:139)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:567)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:541)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:118)
at org.springframework.orm.ibatis.SqlMapClientTemplate$3.doInSqlMapClient(SqlMapClientTemplate.java:295)
at org.springframework.orm.ibatis.SqlMapClientTemplate$3.doInSqlMapClient(SqlMapClientTemplate.java:1)
at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:200)
at org.springframework.orm.ibatis.SqlMapClientTemplate.queryForList(SqlMapClientTemplate.java:293)
at com.bps.dal.dao.dianying.impl.DianYingDaoImpl.getDaoQiDataList(DianYingDaoImpl.java:192)
at com.bps.service.dianying.impl.ToBeRecycledServiceImpl.getDaoQiData(ToBeRecycledServiceImpl.java:300)
at com.bps.service.dianying.impl.ToBeRecycledServiceImpl.insert(ToBeRecycledServiceImpl.java:44)
at com.bps.task.DianYingIBreportTask$Worker.inserttoBeRecycled(DianYingIBreportTask.java:245)
at com.bps.task.DianYingIBreportTask$Worker.run(DianYingIBreportTask.java:203)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
** END NESTED EXCEPTION **
Last packet sent to the server was 1 ms ago.; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred while applying a parameter map.
--- Check the DyDaoImpl_getdaoqilist-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.io.EOFException
STACKTRACE:
java.io.EOFException
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1913)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2304)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2803)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1169)
at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:693)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:794)
at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:168)
at sun.reflect.GeneratedMethodAccessor98.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.ibatis.common.jdbc.logging.PreparedStatementLogProxy.invoke(PreparedStatementLogProxy.java:62)
at com.sun.proxy.$Proxy24.execute(Unknown Source)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:185)
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.sqlExecuteQuery(MappedStatement.java:221)
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:189)
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryForList(MappedStatement.java:139)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:567)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:541)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:118)
at org.springframework.orm.ibatis.SqlMapClientTemplate$3.doInSqlMapClient(SqlMapClientTemplate.java:295)
at org.springframework.orm.ibatis.SqlMapClientTemplate$3.doInSqlMapClient(SqlMapClientTemplate.java:1)
at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:200)
at org.springframework.orm.ibatis.SqlMapClientTemplate.queryForList(SqlMapClientTemplate.java:293)
at com.bps.dal.dao.dianying.impl.DianYingDaoImpl.getDaoQiDataList(DianYingDaoImpl.java:192)
at com.bps.service.dianying.impl.ToBeRecycledServiceImpl.getDaoQiData(ToBeRecycledServiceImpl.java:300)
at com.bps.service.dianying.impl.ToBeRecycledServiceImpl.insert(ToBeRecycledServiceImpl.java:44)
at com.bps.task.DianYingIBreportTask$Worker.inserttoBeRecycled(DianYingIBreportTask.java:245)
at com.bps.task.DianYingIBreportTask$Worker.run(DianYingIBreportTask.java:203)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
** END NESTED EXCEPTION **
Last packet sent to the server was 1 ms ago.
at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:104)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:203)
at org.springframework.orm.ibatis.SqlMapClientTemplate.queryForList(SqlMapClientTemplate.java:293)
at com.bps.dal.dao.dianying.impl.DianYingDaoImpl.getDaoQiDataList(DianYingDaoImpl.java:192)
at com.bps.service.dianying.impl.ToBeRecycledServiceImpl.getDaoQiData(ToBeRecycledServiceImpl.java:300)
at com.bps.service.dianying.impl.ToBeRecycledServiceImpl.insert(ToBeRecycledServiceImpl.java:44)
at com.bps.task.DianYingIBreportTask$Worker.inserttoBeRecycled(DianYingIBreportTask.java:245)
at com.bps.task.DianYingIBreportTask$Worker.run(DianYingIBreportTask.java:203)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
在数据库配置文件中增加配置
datasource.validationQuery=select 1 from dual
datasource.testOnBorrow=true
datasource.testWhileIdle=true
在spring配置文件datasource中增加
打开这个
at com.bps.dal.dao.dianying.impl.DianYingDaoImpl.getDaoQiDataList(DianYingDaoImpl.java:192)
应该是SQL嵌套错误
数据库配置文件添加
datasource.validationQuery=select 1 from dual
datasource.testOnBorrow=true
datasource.testWhileIdle=true
spring配置文件datasource下添加
<property name="validationQuery" value="${datasource.validationQuery}"/>
<property name="testOnBorrow" value="${datasource.testOnBorrow}"></property>
<property name="testWhileIdle" value="${datasource.testWhileIdle}"></property>
你需要保持数据库保持连接,所以楼上所说的加上select 1 from dual,就是用来保持数据库的连接状态。否则长时间没有数据操作,就会断开连接。
这种情况出现的环境很多,众说纷纭。
有文章说在mysql的配置文件里添加waittimeout参数
“MySQL默认的空闲等待时间是8个小时,一旦空闲超过8个小时,就会抛出异常”,mysql是默认每个连接不关闭而等待时长为8小时,但无论什么数据库操作,也不应该持续8小时,而并非那些人所说的mysql空闲了8小时,这完全是两个概念!
个人感觉这种方式完全与解决问题背道而驰,无用的连接非但没有释放,反而一直保持,如果所有访问都使用这一个连接来操作,当然没什么问题,但基本没有人会使用一个连接来处理网站的并发请求吧,试想一下网站有几百上千的并发,那么这些连接将永远会保持,像有些人设置的时间一样,10年。。。。软件运行周期也没这么长吧。
其实归根结底有两点原因会导致出现这样的情况,
1、连接没有关闭释放,从而导致连接死锁。
2、一般发生在并发比较多时,LAG严重,导致很多连接还未结束但到达默认限制时间便被连接池给kill了。
如何避免发生这种情况,
针对第一种:很显然是检查代码,看每次用完连接后有没有及时关闭,一般这里修正了就不会再有问题了。
针对第二种:改连接池默认参数。
以Proxool为例:
3000000//连接空闲限制时间-默认30秒改为5分钟。
代码丢失了,补充
以Proxool为例:
<house-keeping-sleep-time>3000000</house-keeping-sleep-time>
//连接空闲限制时间-默认30秒改为5分钟。