How to remove invalid database connection from pool

后端 未结 4 1977
广开言路
广开言路 2021-02-08 06:22

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

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-08 07:04

    If we want to dispose an ill java.sql.connection from Tomcat jdbc connection pool,

    we may do this explicitly in the program. Unwrap it into an org.apache.tomcat.jdbc.pool.PooledConnection, setDiscarded(true) and close the JDBC connection finally. The ConnectionPool will remove the underlying connection once it has been returned.

    (ConnectionPool.returnConnection(....))

    e.g. PooledConnection pconn = conn.unwrap(PooledConnection.class); pconn.setDiscarded(true); conn.close();

提交回复
热议问题