aspose file tools*
The moose likes JDBC and the fly likes connection validation when db is down Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "connection validation when db is down" Watch "connection validation when db is down" New topic
Author

connection validation when db is down

Hareesh Ram Chanchali
Ranch Hand

Joined: Jan 31, 2005
Posts: 110
The scenario is like this.

A connection pool was configured with application server
Minimum number of connections > 0 were configured.
Hence they will be instantiated at server start up.
I used some of the connections and closed them except one.
Meanwhile DB went down.

The requirement is I want to check if this is a valid connection or not with out using a query (possibly with DUAL) and without using configurable options in application servers ( like TestonReserve).

What could be the simplest way without using the query to check the health of the connection as I need to make sure that it is healthier for next set of steps?

Also for the connection in the above scenario, if I cross check the same with null value, will it validate whether it is healthier or not?
also if I close the connection, will it somehow raise an exception as DB is down? or it will simply logically close the connection and release the same to connection pool irrespective whether DB is up or not?

Apprecaite your insights.

Regards
Hareesh


Hareesh Ram Chanchali
SCJP 5.0, IBM Certified Solution Designer
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2510
    
  10

What could be the simplest way without using the query to check the health of the connection
Why do you reject this functionality? It does exactly what you need.
Just take care that you use a cheap query that returns as least on row, and the pool will do what you want.

I wonder why you don't want to use this mechanism, and whet you suggest as a more appropriate approach for your application.


OCUP UML fundamental and ITIL foundation
youtube channel
adeeb alexander
Ranch Hand

Joined: May 29, 2008
Posts: 268
he requirement is I want to check if this is a valid connection or not with out using a query (possibly with DUAL)


I have seen your requirement just now. you can off course use a query with dual. Its simple use this and see
SELECT SYSDATE FROM DUAL;
Hareesh Ram Chanchali
Ranch Hand

Joined: Jan 31, 2005
Posts: 110
Hi Jan/ Adeeb,

Thanks for the suggestions.
Just wondering about the performance point of view.

Also can con.setAutoCommit(con.getAutoCommit()) be used and catch the SQL exception to know if Connection is still valid or not?

Does the later one improves the efficiency in checking?

Regards
Hareesh
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2510
    
  10

Just wondering about the performance point of view.
Hi,
What performance requirements do you have? Does running the query "select 1 from dual" break this requirement?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: connection validation when db is down