[NOT A CONTRIBUTION] JDBC Pool Version: 9.0.49 Database: Oracle JDBC Version: 19.3.0.0 OS: Mac, Linux prepareStatement created by ProxyConnection returns underlying physical connection not the PooledConnection. Step to reproduce: ConnectionPool pool = ... Connection c = pool.getConnection(); PreparedStatement ps = c.createPreparedStatement(); assertTrue(c == ps.getConnection()) // return false
Have you set org.apache.tomcat.jdbc.pool.interceptor.StatementDecoratorInterceptor? This interceptor is available for prevents access to the actual connection. see https://tomcat.apache.org/tomcat-9.0-doc/jdbc-pool.html#org.apache.tomcat.jdbc.pool.interceptor.StatementDecoratorInterceptor
That helped. I'm surprised to see that it is not a default behavior. Any plans to change this?
It's probably a performance consideration NOT to wrap the connections returned by Statement.getConnection(). Do you find different behavior if you use Tomcat's default database connection pool (the one based upon commons DBCP2)?
Closing this as a duplicated. *** This bug has been marked as a duplicate of bug 48392 ***