I usually use SELECT 1tomcat jdbc as my preferred query for checking from pools, because it returns only one row with the result 1 , which is very fast, but today I found one terrible error:
My database only has one table with its main key and cannot be null . Sometimes this table is discarded and then reappears by the application. And what a problem, SELECT 1check the database connection, because it is already up, but the table is missing, so I get a terrible exception.
So, decisions go through finding one check request on a single table that exists in the database. In addition, I need the request to be as fast as possible, because application performance is one of the main tasks.
You can answer what the obvius query can be SELECT 1 FROM THE_TABLE, but this query returns 1 for each row of the table, and it is not very fast.
So, what could be a faster validation query on this table?
EDIT
If I need to return at least one result, How should the verification request be?
I ask this because some pool implementations, such as commons-dbcp, do not accept a query without results as a valid query.