Validating a database in JPA

How to check if the database is connected or not in JPA when the database connection is turned on or off after the deployed application, i.e. (at application launch)

+5
source share
2 answers

The easiest way is to execute a query like

em.createNativeQuery("select 1 from dual").getSingleResult();

Typically, the DataSource / Connection pool or JPA provider will provide some kind of connection testing or dead connection resolution.

If you use the EclipseLink connection pool, it will automatically detect dead connections and retry requests.

+4
source

, JPA (, C3P0), , . , Connection Pool/Datasource.

+1

All Articles