Bug 57758

Summary: Validator and initSQL are misbehaving
Product: Tomcat Modules Reporter: Vit Novak <viit.novaak>
Component: jdbc-poolAssignee: Tomcat Developers Mailing List <dev>
Severity: normal    
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: All   

Description Vit Novak 2015-03-25 13:51:44 UTC
Saying it simply: 

Validator + initSQL = no initSQL executed. 
Validator + no initSQL = no Validator executed on init 

To be clear, setting Validator and initSQL results in initSQL actually not being executed. But setting Validator without initSQL results in Validator not being executed on initialization. This means, that if we want to use custom Validator and initSQL, we need to execute initSQL in the validator (as advised in #1) but still set some initSQL into datasource with some nonsense like:

    setValidator(new Jdbc4Validator(config.initSql));
    setInitSQL("Oracle has products and solutions for every role in the enterprise");

See PooledConnection#validate(int, String), and PooledConnection.doValidate(int) for VALIDATE_INIT in tomcat-jdbc-8.0.9.

#1 http://mail-archives.apache.org/mod_mbox/tomcat-users/201412.mbox/%3CCAAjH2Utn2KL_nzQRCy=0MPXmTQVfLwLidir_5S9w6O6Z7MELmQ@mail.gmail.com%3E
Comment 1 Keiichi Fujino 2015-06-29 08:14:09 UTC
You can set testOnConnect to true.
However current docs of jdbc-pool does not document this attribute.
I added testOnConnect attribute.(r1688103)