Problem with isValid ()

0

I am using the Tomcat Connection Pool to access my database so that I get the connections with the following code:

  public DBQueryResult query(String sentencia)  throws Exception
  {
    PreparedStatement stmt = null;
    ResultSet rs = null;
    try
    {
      if(conn==null || !conn.isValid(DBConnection.TIMEOUT_SECONDS_CHECK_VALID_CONN)) conn = getConnection(); 
 ...
}

The fact is that from time to time on the line that uses the isValid () method, it throws the following exception:

java.sql.SQLException: Connection has already been closed.
    at org.apache.tomcat.jdbc.pool.ProxyConnection.invoke(ProxyConnection.java:117)
    at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:108)
    at org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor.invoke(AbstractCreateStatementInterceptor.java:70)
    at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:108)
    at org.apache.tomcat.jdbc.pool.interceptor.ConnectionState.invoke(ConnectionState.java:152)
    at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:108)
    at org.apache.tomcat.jdbc.pool.TrapException.invoke(TrapException.java:40)
    at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:108)
    at org.apache.tomcat.jdbc.pool.DisposableConnectionFacade.invoke(DisposableConnectionFacade.java:81)
    at com.sun.proxy.$Proxy0.isValid(Unknown Source)
    at db3.DBConnection.query(DBConnection.java:80)
    at db3.generateFilter(Filter.java:808)

I understood that isValid () was checking that the connection was valid but when in line 808 of Filter.java I use query () it tells me to throw that exception and I do not understand why. It is assumed that if the connection is not valid, it would request a new one to the pool. What am I missing? Thanks.

    
asked by Julie 17.12.2017 в 17:02
source

0 answers