• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

connection validation when db is down

 
Hareesh Ram Chanchali
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jan Cumps
Bartender
Posts: 2602
13
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
adeeb alexander
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2602
13
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic