Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JDBC and the fly likes detecting liveliness of connection Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "detecting liveliness of connection" Watch "detecting liveliness of connection" New topic
Author

detecting liveliness of connection

Pushker Chaubey
Ranch Hand

Joined: Dec 06, 2006
Posts: 53
How can I detect Liveliness of connection object?
The situation is like this. I have a monitor application which needs to monitor the database and some applications which togeather with the database forms a complete system. As soon as the database goes down, monitor application sends signals to other application to shut them down.
The problem is - how can I detect from my monitor application that database is down. The monitoring application also maintains a pool of connection to database for some purpose. Is there some way to use the existing connections to detect the liveliness of database?

Thanks.


Regards,<br />Pushker<br /> <br />SCBCD 5.0 90%<br />SCWCD 5.0 89%<br />SCJP 5.0 90%
Herman Schelti
Ranch Hand

Joined: Jul 17, 2006
Posts: 387
hi Pushker,

you could do a select ... from ... to see if your databse is still up and running (if not you will get an SQL-exception)

Herman
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 14491
    
    7

Originally posted by Herman Scheltinga:
hi Pushker,

you could do a select ... from ... to see if your databse is still up and running (if not you will get an SQL-exception)

Herman


... which is basically what the 'keep-alive' logic in the apache dbcp does, if switched on. If the request fails, the Connection is discarded and a new one is obtained. Otherwise the existing Connection is passed out of the pool for the benefit of the user.

I believe a safe, general-purpose test for Oracle is 'SELECT 1 from dual'.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: detecting liveliness of connection
 
Similar Threads
Help please!!! Is there a method for closing sessions java-side?
Detect overloaded web, application or database server
Cancel JDBC Connection when Browser Cancel
Is there some help available with WebLogic
JDBC monitoring