When you are maintaining DB connections, it is always recommended to use a validationQuery to check the health of the TCP connection of the connections stay in DB connection pool.
Because the connection opening is an expensive and time consuming operation, after a connection is created, it will be kept open for a specific time in the pool. When re-using these connections from the pool, there can be situations that the TCP connection to the DB is interrupted and the connection consumer gets errors such as communication link failures etc..
In order to avoid that, a validationQuery, an SQL statement specific to DBMS type, can be used which runs before using the connection.
In WSO2 middleware platform, you usually use central governance/configuration registry to store SOA metadata and various governance tasks. Governance registry supports multiple DBs as underlying data stores. You establish the connection to DB in CARBON_HOME/repository/conf/registry.xml as follows.
This is one of the places where you may experience DB connection issues as I explained above. Therefore, it is always a best practice to use a validationQuery.
If your DBMSs is MySQL or MSSQL, then use the following.
<validationQuery>SELECT 1 FROM DUAL</validationQuery>
<validationQuery>SELECT version(); </validationQuery>
Similarly, when you make DB connections in WSO2 Data Services Server, make sure to use validationQuery in data source definition section as follows.