Jiby Jose
Jiby Jose

Reputation: 3845

Check if connection of database is live in hibernate

In mysql before critical database operations i am checking if connection to database is live running a simple query mostly

 select now()

Can there be a suitable alternative in hibernate not selecting from any tables but selecting anything generic like current time in earlier case to check if connection to database is live.

Thanks

Upvotes: 0

Views: 4505

Answers (1)

mindas
mindas

Reputation: 26703

This is normally done not at Hibernate but at connection pool configuration level.

E.g. c3p0 has idle_test_period, preferredTestQuery and testConnectionOnCheckout; dbcp has validationQuery and so on.

As for SQL, I don't believe something generic exists. But there's a similar SO question for this purpose already.

Upvotes: 1

Related Questions