2

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;
      }
}
Federico Alvariz
  • 81
  • 1
  • 2
  • 4
  • https://bz.apache.org/bugzilla/show_bug.cgi?id=48817. I cannot tell from the report if this was implemented or not but surely you are not the first one to ask this question. – peterh Oct 01 '16 at 22:47

1 Answers1

0

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.

Community
  • 1
  • 1
bdulac
  • 1,686
  • 17
  • 26