当前位置: 首页 > Java > 正文

mybatis Could not get JDBC Connection错误排查

关键字:
1 星2 星3 星4 星5 星 (2 次投票, 评分: 5.00, 总分: 5)
Loading ... Loading ...
baidu_share

今天在日志中发现以下错误:

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: An SQLException was provoked by the following failure: com.mchange.v2.resourcepool.ResourcePoolException: Attempted to use a closed or broken resource pool
### The error may exist in com/hq/es/forum/dao/mappers/ForumCountryDaoMapper.xml
### The error may involve com.hq.es.forum.dao.ForumCountryDaoMapper.getLastUpdatetimeCountry
### The error occurred while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: An SQLException was provoked by the following failure: com.mchange.v2.resourcepool.ResourcePoolException: Attempted to use a closed or broken resource pool
	at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:365)
	at $Proxy9.selectOne(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:160)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:95)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:40)
	at $Proxy26.getLastUpdatetimeCountry(Unknown Source)
	at com.hq.es.forum.service.country.impl.ForumCountryServiceImpl.getLastUpdatetimeCountry(ForumCountryServiceImpl.java:78)
	at com.hq.es.forum.service.combination.impl.ForumCombinationServiceImpl.deltaImportIndexCountry(ForumCombinationServiceImpl.java:128)
	at com.hq.es.forum.schedule.ForumScheduleJob.forumDeltaImportIndex(ForumScheduleJob.java:73)
	at sun.reflect.GeneratedMethodAccessor145.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:273)
	at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:311)
	at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:113)
	at org.quartz.core.JobRunShell.run(JobRunShell.java:223)
	at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)
Caused by: org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: An SQLException was provoked by the following failure: com.mchange.v2.resourcepool.ResourcePoolException: Attempted to use a closed or broken resource pool
### The error may exist in com/hq/es/forum/dao/mappers/ForumCountryDaoMapper.xml
### The error may involve com.hq.es.forum.dao.ForumCountryDaoMapper.getLastUpdatetimeCountry
### The error occurred while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: An SQLException was provoked by the following failure: com.mchange.v2.resourcepool.ResourcePoolException: Attempted to use a closed or broken resource pool
	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:104)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:95)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:59)
	at sun.reflect.GeneratedMethodAccessor66.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:355)
	... 16 more
Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: An SQLException was provoked by the following failure: com.mchange.v2.resourcepool.ResourcePoolException: Attempted to use a closed or broken resource pool
	at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
	at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:80)
	at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:66)
	at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:279)
	at org.apache.ibatis.executor.ReuseExecutor.prepareStatement(ReuseExecutor.java:72)
	at org.apache.ibatis.executor.ReuseExecutor.doQuery(ReuseExecutor.java:53)
	at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267)
	at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:141)
	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:105)
	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:81)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:101)
	... 22 more
Caused by: java.sql.SQLException: An SQLException was provoked by the following failure: com.mchange.v2.resourcepool.ResourcePoolException: Attempted to use a closed or broken resource pool
	at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
	at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:65)
	at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:62)
	at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:531)
	at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
	at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
	at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
	... 32 more
Caused by: com.mchange.v2.resourcepool.ResourcePoolException: Attempted to use a closed or broken resource pool
	at com.mchange.v2.resourcepool.BasicResourcePool.ensureNotBroken(BasicResourcePool.java:1632)
	at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:524)
	at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
	at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
	... 35 more

以为当时是数据库连接不了,经过排查,数据库连接正常。

看提示错误出现在com.hq.es.forum.dao.ForumCountryDaoMapper.getLastUpdatetimeCountry上,该sql为:

	<select id="getLastUpdatetimeCountry" resultType="ForumCountryBean" useCache="true">
		SELECT COUNT(*) AS currentCount, MAX(t1.updated_time) AS updatetime 
		FROM hq_common_forum  t1
		WHERE t1.updated_time >= #{lastDeltaUpdatetime}
	</select>

在windows测试环境下,一切正常。但是在linux环境下一直出错。
最后将sql语句改为:

	<select id="getLastUpdatetimeCountry" resultType="ForumCountryBean" useCache="true">
		SELECT COUNT(*) AS currentCount, MAX(t1.updated_time) AS updatetime 
		FROM hq_common_forum  t1
		<where>
			<![CDATA[t1.updated_time >= #{lastDeltaUpdatetime}]]>
		</where>
	</select>

一切ok。

本文固定链接: http://www.chepoo.com/mybatis-could-not-get-jdbc-connection-error-troubleshooting.html | IT技术精华网

mybatis Could not get JDBC Connection错误排查:等您坐沙发呢!

发表评论