It's not a secret anymore!
The moose likes JDBC and Relational Databases and the fly likes Handling stale connections Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Handling stale connections" Watch "Handling stale connections" New topic

Handling stale connections

Venkat Sadasivam
Ranch Hand

Joined: May 10, 2008
Posts: 139
Hi, How to handle stale connections? The application hangs when database server restarts.

“Any fool can write code that a computer can understand. Good programmers write code that humans can understand. ”<br>
-Martin Fowler
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3753

Catch them and reconnect? If a connection dies, the application will throw an exception after some timeout value. You can catch these exceptions and decide a recovery path. You could also set up a polling thread to monitor the database status although this might be overkill.

[OCA 8 Book] [Blog]
I agree. Here's the link:
subject: Handling stale connections
It's not a secret anymore!