-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: How to test if username/password to database are valid
PostPosted: Sun Feb 11, 2007 1:03 pm 
Newbie

Joined: Sun Feb 11, 2007 12:04 pm
Posts: 2
Hello,
how to test if the connection to database is valid?
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, connection is valid.

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.

_________________
---------------------
Jakub Maler
www.simpleway.cz


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.