You want to increase the test/validation of connections in the connection pool to prevent the database from thinking that the connection is dead and that the Web application server thinks the connection is still valid in the "Timeout problem with connector/j connection to MySQL in Tomcat" post. The MySQL documentation mentions the examples in the Tomcat document are validationquery, but there are a lot of posts on the web that are written by Testquery, which one does it use?
This is related to the implementation of the connection pool:
connection Pooling Implementation |
the Feature property 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 Analysis Atomikos data Connection pool source code, understand Testquery |
Testquery |
Also, the SQL statement that tests/verifies connection pooling connections varies by database:
Efficient SQL test query or validation query that would work across all (or most) databases
Dbcp-validationquery for different Databases
Combining the two posts, the summary results are as follows:
Database |
test/Validate Query |
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 or SELECT Current date from sysibm.sysdummy1 |
Apache Derby |
VALUES 1 from SYSIBM. SYSDUMMY1 or SELECT 1 from SYSIBM. SYSDUMMY1 |
Hsqldb |
SELECT 1 from any_existing_table WHERE 1=0 or SELECT 1 from INFORMATION_SCHEMA. System_users |
Informix |
Select COUNT (*) from Systables |
Testquery/validationquery settings for the JDBC Connection pool