For Oracle database: you may use the Connection object with query of "select 1 from dual"; if the query returns the result, then it is a valid Connection object.
For MySQL database: you may use the Connection object with query of "select 1"; if the query returns the result, then it is a valid Connection object.