If testOnBorrow is set true, testOnConnect is false, and validationQuery is an illegal query, the current implementation will hide the fact that validationQuery never succeeds. The offending code is in org.apache.tomcat.jdbc.pool.ConnectionPool line 797. 790 //if we reached here, that means the connection 791 //is either has another principal, is discarded or validation failed. 792 //we will make one more attempt 793 //in order to guarantee that the thread that just acquired 794 //the connection shouldn't have to poll again. 795 try { 796 con.reconnect(); 797 if (con.validate(PooledConnection.VALIDATE_INIT)) { Instead, con.validate(PooledConnection.VALIDATE_BORROW) should be called.
Or better, something akin to con.validate(PooledConnection.VALIDATE_INIT | PooledConnection.VALIDATE_BORROW).
Thank you for the report, tricky indeed. Fixed in r1616625