File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Elasticsearch in Action this week in the Big Data forum!
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: 3739

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]
rocket mass heater kickstarter
subject: Handling stale connections