如何从池中删除无效的数据库连接 [英] How to remove invalid database connection from pool

查看:107
本文介绍了如何从池中删除无效的数据库连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 tomcat oracle 数据库的连接池.它工作正常,但是当我长时间使用我的应用程序时,出现错误"连接重置".我收到此错误的原因是,在tomcat数据源的逻辑连接关闭之前,oracle服务器的物理连接已关闭.因此,在从数据源获取连接之前,我正在使用连接对象的 isValid(0)方法检查连接有效性,如果物理连接已关闭,则该方法为false.但是我不知道如何从池中删除无效连接对象.

I am using connection pooling of tomcat with oracle database. It is working fine, but when i use my application after a long time it is giving error that "connection reset". I am getting this error because of physical connection at oracle server closed before logical connection closed at tomcat datasource. So before getting the connection from datasource i am checking the connection validity with isValid(0) method of connection object which gives false if the physical connection was closed. But i don't know how to remove that invalid connection object from the pool.

推荐答案

我在 server.xml 文件中配置数据源时使用了 validatationquery .在提供给应用程序之前,它将通过在数据库中执行查询来检查连接的有效性.

I used validatationquery while configuring the datasource in server.xml file. It is going to check the validity of the connection by executing the query at database before giving to the application.

对于 Oracle

validationQuery="/* select 1 from dual */"

用于 MySql

validationQuery="/* ping */"

这篇关于如何从池中删除无效的数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆