This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes Detecting database connection loss Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Detecting database connection loss" Watch "Detecting database connection loss" New topic
Author

Detecting database connection loss

Pascal Got
Greenhorn

Joined: Mar 05, 2002
Posts: 23
Hi,
I have an app which connects to a database and perform some query (using SELECT "style" and stored proc) - all working well.
But is there a way to detect loss a connection to my database as soon as it happens (is there an exception or event trigger I can catch or listen to) ? ( so I can auto-reconnect)
Currently, I see loss of connection when I do a query .... which is too late really...
Thx for your help.
Pascal
SJ Adnams
Ranch Hand

Joined: Sep 28, 2001
Posts: 925
in the connection pool we a have a thread that does a 'select * from dual' at every timeperiod in a property file.
why are you getting kicked off? is there a timeout or something in the profile?
Pascal Got
Greenhorn

Joined: Mar 05, 2002
Posts: 23
Originally posted by Simon Lee:

why are you getting kicked off? is there a timeout or something in the profile?

No, but we depend on adatabase server which (very rarely) may be bounced... as our system is a 24/7 system, unless we get notify and reconnect, we don't see the connection being dropped.....
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
It really depends on the implemetation of your connection pool. JDBC 2.0 std ext. has the class javax.sql.ConnectionEventListener these can be created and attached to each Connection in the Pool. It's distribute now with JDK 1.4. Your pool can implement this and on notification of sever Exception, cleanup the current connections and create a new good set for the pool. http://java.sun.com/j2se/1.4.1/docs/api/javax/sql/ConnectionEventListener.html
[ April 25, 2003: Message edited by: Carl Trusiak ]

I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Detecting database connection loss
 
Similar Threads
Fetch data from different database schema tables
visual J++ and retreiving rows from sql server
Database Reconnection mechansim at resultset level
Transfer Excel Sheet information to database
JDBC Error