-->
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.  [ 3 posts ] 
Author Message
 Post subject: Exception for bad connection to the db
PostPosted: Mon May 08, 2006 1:49 pm 
Newbie

Joined: Mon May 08, 2006 12:53 pm
Posts: 2
Hi folks,
On the loading of my application i want to test the establishement of connection to the db.
For this, i opened a session to see if i could connect to the db but the problem is that there is no thrown exception when there is there is a bad connection string.
Is there any method in hibernate that throw an exception for connection failing? or there is another way to test the connection?
Thx,
Amine.
Code:


sessionFactory = new Configuration().configure().buildSessionFactory();
Session s = sessionFactory.openSession();
.
Hibernate version: 3.1


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 08, 2006 2:26 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
Maybe you want to check with one more call to see if connection is established.

Code:
sessionFactory = new Configuration().configure().buildSessionFactory();
Session s = sessionFactory.openSession();
try {
   session.connection();
} catch ( HibernateException hiberException ) {
   //....
}


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 08, 2006 2:52 pm 
Regular
Regular

Joined: Wed Jul 27, 2005 2:33 am
Posts: 118
Remember to close the connection in a finally block. You might want to check the API at:

http://www.hibernate.org/hib_docs/v3/api/org/hibernate/Session.html#connection()

which explains whether you have to close the connection or not after use.


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

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.