• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Detect a lost of connection.

 
Nicolas Lavacry
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How could I detect correctly a lost of connection without exception catching ?

Is there any listener or method to implement ?

Best Regards.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. Its exceptions or nothing.
 
Andy Nimmo
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul,

That's not strictly true. Although exceptions are the best way of dealing with an occurance of a showstopping situation there are other ways to do things.

In this example Nicolas wants to just check if the connection is still alive and well which can be done quickly and easily without waiting for an exception to be thrown.

Have a look at the following code which I am using in one of my database access classes:



This simple example checks to see if the connection is alive before it attempts to send a Query. If the connection isn't alive then it attempts a single re-establishment of the connection before failing.

Hope this helps.

Andy.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doh! Well caught Andy. That will teach me to answer questions without double checking the docs.
 
ramandeep mann
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But What if query is already been fired and server is waiting for reply.On the other side Firewall or something else drop the connection before receiving the reply.I am in such a situation

========================
We have such a query which takes more then 2 hours and database is on other machine.But my application server is behind the firewall so this firewall is dropping the ideal connection (waiting for results )after every hour .

========================
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic