I would like to validate a jdbc connection using tomcat 7 jdbc pool using JDBC4 Connection.isValid instead of a validation Query.
I am wondering if implementing a Validator like bellow would be enough. Also I am wondering which would be a nice timeout.
Thanks in advance! Fede
PS: I am using oracle 11g.
public class MyValidator implements Validator{
public static final int DEFAULT_TIMEOUT = 5;
public boolean validate(final Connection c, final int validateAction){
try{
return c.isValid(DEFAULT_TIMEOUT);
}catch(Exception e){
// LOG e
return false;
}
}
A debugger would help you troubleshoot the situation: Tomcat / DBCP connection pools do not return a raw connection but a wrapper/adapter that recycle underlying "true" connections. The pool usually checks the connections by itself (reconnect if needed) and, I guess, does not allow to really validate.
You have more info about the pool validation parameters in the Tomcat doc. Another exchange deals about JBoss pools wrapping Oracle connections, what is a common practice.