Oracle – JDBC Validation Query

jdbcoracle

By default for Oracle Databases validation query is "select 1 from dual".
Tomcat says:

ValidationQuery – If specified, this query MUST be an SQL SELECT
statement that returns at least one row.

Based on sentences above, can I modify a validation query that will be:

  1. nested or conditioned query
  2. from another table I specify
  3. this table has one row and multiple columns

I've read a lot of documentation, but didn't find any information to say that's impossible or at least incorrect.

Best Answer

Yes, it can be any valid query - from the Tomcat JDBC documentation:

(String) The SQL query that will be used to validate connections from this pool before returning them to the caller. If specified, this query does not have to return any data, it just can't throw a SQLException. The default value is null. If not specified, connections will be validation by the isValid() method. Example values are SELECT 1(mysql), select 1 from dual(oracle), SELECT 1(MS Sql Server)

You asked about using nested queries, different tables and multiple columns and so I give you something to think about:

The validationQuery is executed every time an application requests a connection from the pool. This is before the application issues it's own query - so at a minimum you issue two queries against the database. With that in mind, why would you want to make the query more complex? All you would do is add unnecessary load on the database server for no reason at all - AFAIK you cannot see the output of the validationQuery within a Java application because it happens at the container level before the connection is passed to the client.

Keep it simple and use one of the recommended queries.