JDBC connection pool testQuery/validationQuery settings

 In the post " Timeout problem of using Connector/J to connect to MySQL in Tomcat ", I want to increase the test/verification of the connection in the connection pool to prevent the database from thinking that the connection is dead and the Web application server thinks that the connection is still valid. The example in the Tomcat documentation uses validationQuery, but there are still many posts on the Internet that write testQuery. Which one should I use?


It turns out that this is related to the implementation of the connection pool: The connection pool implements the function attribute name
The Tomcat JDBC Connection Pool validationQuery
The Apache Commons DBCP Connection Pool validationQuery
c3p0 - JDBC3 Connection and Statement Pooling preferredTestQuery
Atomikos: Tomcat Spring ActiveMQ MySQL JMX Integration
analyzes the source code of Atomikos data connection pool and finds out testQuery
testQuery

In addition, the SQL statements for testing/validating connection pool connections also vary by database:
Efficient SQL test query or validation query that will work across all (or most) databases
DBCP - validationQuery for different Databases

Combining the above two posts, the summary results are as follows:
Database test/validation queries
MySQL SELECT 1
PostgreSQL SELECT 1
Microsoft SQL Server SELECT 1
SQLite SELECT 1
H2 SELECT 1
Ingres SELECT 1
Oracle select 1 from dual
DB2 select 1 from sysibm.sysdummy1 或
SELECT current date FROM sysibm.sysdummy1
Apache Derby VALUES 1 FROM SYSIBM.SYSDUMMY1 或
SELECT 1 FROM SYSIBM.SYSDUMMY1
HSQLDB SELECT 1 FROM any_existing_table WHERE 1=0 或
SELECT 1 FROM INFORMATION_SCHEMA.SYSTEM_USERS
Informix select count(*) from systables

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326861723&siteId=291194637