DBCP - validationQuery for different databases

I am using the DBCP pool and I want to use testOnBorrow and testOnReturn to verify that the connection is working.
Unfortunately, I have to set the validationQuery property for it to work.

Question: What value should be in validationQuery?

I know that: validationQuery must be an SQL SELECT statement that returns at least one row.

The problem is that we use different databases (DB2, Oracle, hsqldb).

+71
java connection-pooling apache-commons-dbcp
May 21 '12 at 11:20
source share
3 answers

There is more than one validationQuery for all databases. In each database, you must use different validationQuery.

After hours of searching and testing, I put together this table:

Validate Database Validation

  • hsqldb - select 1 from INFORMATION_SCHEMA.SYSTEM_USERS
  • Oracle - select 1 from dual
  • DB2 - select 1 from sysibm.sysdummy1
  • mysql - select 1
  • Microsoft SQL Server - select 1 (tested on SQL Server 9.0, 10.5 [2008])
  • postgresql - select 1
  • ingres - select 1
  • derby - values 1
  • H2 - select 1
  • Firebird - select 1 from rdb$database

I wrote a validation request for various databases on this blog.

There is an example class in advance that returns validationQuery according to the JDBC driver.

Or does anyone have a better solution?

+170
May 21 '12 at 11:21
source share

For MySQL with the Connector / J driver, there is an easy validation request that simply sends ping to the server and returns a dummy result set. A validation request can be (or must begin with) exactly the following line:

 /* ping */ 

For more information, see β€œ Confirming Connections” in the MySQL manual.

+10
Dec 26 '13 at 9:10
source share

For Informix, validation request, select 1 from systables

0
Jun 26 '15 at 22:06
source share



All Articles