问题:当服务放置一段时间后,再次调用会提示:The connection does not exist.; nested exception is java.sql.SQLException: The connection does not exist.一直不知如何解决,直到看到了这篇博文才有了解决问题的思路。
解决方案:之前我在tomcat7/conf/context.xml下是这样配置jndi的
<Resource
global="as400"
auth="Container"
name="jdbc/as400"
type="javax.sql.DataSource"
driverClassName="com.ibm.as400.access.AS400JDBCDriver"
url="jdbc:as400://localhost;libraries=test,*LIBL;errors=full"
username="xxx"
password="xxx"
/>
解决问题的配置如下:
增加检查连接的可用性,dbcp定时检测连接与重连
<Resource
global="as400"
auth="Container"
name="jdbc/as400"
type="javax.sql.DataSource"
driverClassName="com.ibm.as400.access.AS400JDBCDriver"
url="jdbc:as400://localhost;libraries=test,*LIBL;errors=full"
username="xxx"
password="xxx"
maxActive="100"
maxIdle="30"
maxWait="10000"
logAbandoned="true"
validationQuery="select 1 from sysibm.sysdummy1"
testWhileIdle="true"
timeBetweenEvictionRunsMillis="8000"
minEvictableIdleTimeMillis="10000"
/>
原因分析:
默认配置的DBCP连接池,是不对池中的连接做测试的,有时连接已断开了,但DBCP连接池不知道,还以为连接是好的,应用从池中取出这样的连接访问数据库一定会报错的。