views:

16

answers:

2

I am working with mysql5 and hibernate. I am running my application in tomcat application server. if i stop mysqld service for some seconds, i am getting exception: java.sql.SQLException: Unable to connect to any hosts due to exception: java.net.ConnectException: Connection refused: connect If i will start service again, old hibernate session will be lost. I want to listen 3306 port number for some seconds to check whether service has started or not. If not, then i want to terminate my application by showing proper reason.

A: 

Why you do not just catch the exception thrown from the Java and in case you can not connect. Go into a cycle for 3-4 seconds that checks every second if the connection is avaliable again? In the cycle put a "sleep" command for the application to wait 1 second before it checks again and if after 3-4 seconds depending on your choice you still can not connect dispaly a error message.

Yasen Zhelev
I will check whether sessionFactory.openSession() returns a session or null. if it will be null then i should show one error message on application. but my application GUI is in FLEX. can i show this error in a dialog box from HibernateUtil class?
divi
A: 

you can opening a socket on your sql port and handle connection exception

remi bourgarel