Hello,
how to test if username and password to database are correct (and generally, connection settings) ?
I use this code (and I also use C3P0 connection pooler):
Code:
Session s = getSessionFactory().getCurrentSession();
s.beginTransaction();
s.connection().createStatement();
s.getTransaction().commit();
When no exception happened, username and password are correct.
But this approcha looks ugly to me and I have also problem that when connection isn't valid, hibernate try to connect for cca. 30 seconds and entire application freezes (even if connection test runs in separate thread).
Is there any other possibility how to test it, or at least how to force hibernate to test database connection for only 5 seconds or to force hibernate not to "freeze" application?
Thank you for your answers.