请问用spring+ibatis时,tomcat服务器一直启动着,但是如果长时间不访问网页,相隔估计8个小时以上,再访问网页时,就会报出下面的错误,在刷新网页就可以访问了,请问为什么????
[code="java"]HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.springframework.dao.DataAccessResourceFailureException: SqlMapClient operation; SQL [];
--- The error occurred in com/wanmei/wa/dao/ibatis/ibatis-wangbz.xml.
--- The error occurred while applying a parameter map.
--- Check the ibatis-wangbz.getUser-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: java.sql.SQLException: Io 异常: Connection reset; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in com/wanmei/wa/dao/ibatis/ibatis-wangbz.xml.
--- The error occurred while applying a parameter map.
--- Check the ibatis-wangbz.getUser-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: java.sql.SQLException: Io 异常: Connection reset
org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:253)
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:203)
org.springframework.orm.ibatis.SqlMapClientTemplate.queryForList(SqlMapClientTemplate.java:293)
com.wanmei.wa.dao.ibatis.IbatisDao.queryForList(IbatisDao.java:37)
com.wanmei.wa.business.impl.LoginBusinessImpl.getSessionUser(LoginBusinessImpl.java:44)
com.wanmei.wa.util.LoginFilter.doLogin(LoginFilter.java:80)
com.wanmei.wa.util.LoginFilter.doFilter(LoginFilter.java:63)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88)
root cause
com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in com/wanmei/wa/dao/ibatis/ibatis-wangbz.xml.
--- The error occurred while applying a parameter map.
--- Check the ibatis-wangbz.getUser-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: java.sql.SQLException: Io 异常: Connection reset
com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:201)
com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryForList(MappedStatement.java:139)
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:567)
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:541)
com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:118)
org.springframework.orm.ibatis.SqlMapClientTemplate$3.doInSqlMapClient(SqlMapClientTemplate.java:295)
org.springframework.orm.ibatis.SqlMapClientTemplate$3.doInSqlMapClient(SqlMapClientTemplate.java:1)
org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:200)
org.springframework.orm.ibatis.SqlMapClientTemplate.queryForList(SqlMapClientTemplate.java:293)
com.wanmei.wa.dao.ibatis.IbatisDao.queryForList(IbatisDao.java:37)
com.wanmei.wa.business.impl.LoginBusinessImpl.getSessionUser(LoginBusinessImpl.java:44)
com.wanmei.wa.util.LoginFilter.doLogin(LoginFilter.java:80)
com.wanmei.wa.util.LoginFilter.doFilter(LoginFilter.java:63)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88)
root cause
java.sql.SQLException: Io 异常: Connection reset
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:162)
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:274)
oracle.jdbc.driver.T4CPreparedStatement.execute_for_describe(T4CPreparedStatement.java:432)
oracle.jdbc.driver.OracleStatement.execute_maybe_describe(OracleStatement.java:896)
oracle.jdbc.driver.T4CPreparedStatement.execute_maybe_describe(T4CPreparedStatement.java:452)
oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:986)
oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2888)
oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:2979)
com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.execute(NewProxyPreparedStatement.java:989)
com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:185)
com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.sqlExecuteQuery(MappedStatement.java:221)
com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:189)
com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryForList(MappedStatement.java:139)
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:567)
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:541)
com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:118)
org.springframework.orm.ibatis.SqlMapClientTemplate$3.doInSqlMapClient(SqlMapClientTemplate.java:295)
org.springframework.orm.ibatis.SqlMapClientTemplate$3.doInSqlMapClient(SqlMapClientTemplate.java:1)
org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:200)
org.springframework.orm.ibatis.SqlMapClientTemplate.queryForList(SqlMapClientTemplate.java:293)
com.wanmei.wa.dao.ibatis.IbatisDao.queryForList(IbatisDao.java:37)
com.wanmei.wa.business.impl.LoginBusinessImpl.getSessionUser(LoginBusinessImpl.java:44)
com.wanmei.wa.util.LoginFilter.doLogin(LoginFilter.java:80)
com.wanmei.wa.util.LoginFilter.doFilter(LoginFilter.java:63)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.26 logs.
Apache Tomcat/6.0.26[/code]
附上datasource.properties
[code="java"]########################################
########################################
c3p0.acquireIncrement=3
c3p0.initialPoolSize=4
c3p0.maxPoolSize=64
c3p0.minPoolSize=4
c3p0.maxIdleTime=25200
c3p0.maxIdleTimeExcessConnections=1800
c3p0.checkoutTimeout=6000
c3p0.idleConnectionTestPeriod=18000
c3p0.preferredTestQuery='select 1 from daul'[/code]
不清楚oracle有没有这个8小时的问题,不过我相信应该也有。要不然connection pool里的有些connection可能就永远无法释放。mysql是8小时不活动的connection就会由数据库端释放,而在这时pool并不知道这个情况,这时再试图去使用这个connection,就会出现你说的那种问题。
这和TOMCAT ibatis无关
应用程序和数据库建立连接,如果超过8小时应用程序不去访问数据库,数据库就断掉连接缺省 mysql的timeout时间是28800秒,也就是8小时,增加一个0就没问题了。
这是mysql 8小时的问题。加入如下:
c3p0.timeBetweenEvictionRunsMillis=10000
c3p0.minEvictableIdleTimeMillis=60000
一定就可以了。
不好意思,错了,这是dhcp的配置方法,你自己找一下c3p0的数据库怎么配置,就搜索一下"c3p0 mysql 8小时"就可以了。