| Author |
Checking connection status
|
karthic panneer
Ranch Hand
Joined: Sep 22, 2008
Posts: 57
|
|
Hi I am using connection pooling in struts and it works fine also. But if there is connection failure in network how can we find that the there is no connections in connection pool or how can we test the connection is live or not without producing exception. Because in such conditions when i use then it produces exceptions. Anybody have idea please inform me. Thanks in advance Karthic
|
 |
Makesh Kumar Ramakrishnan
Ranch Hand
Joined: Jan 07, 2006
Posts: 88
|
|
|
What I would do is, catch the exception assuming that Exception is thrown because of network connection failure. In that catch block, you can write your connection failure recovery mechanism.
|
Makesh<br /> <br />SCJP | SCWCD | SCBCD | SCEA
|
 |
Jan Cumps
Bartender
Joined: Dec 20, 2006
Posts: 2343
|
|
Would a validation query help you? If you provide one, your connection pool will first try to execute that query. If this query fails, the pool discards the bad connection, and gets a fresh connection for you. Regards, Jan (assuming you are using the Apache connection pool)
|
OCUP UML fundamental
ITIL foundation
|
 |
karthic panneer
Ranch Hand
Joined: Sep 22, 2008
Posts: 57
|
|
Thanks for your Reply Yes i have used validation query though i got exception. I think the dbcp class will try execute that query when a getConnection()called, so that might produce the exception Am i right Thanks Karthic.p
|
 |
Jan Cumps
Bartender
Joined: Dec 20, 2006
Posts: 2343
|
|
I think the dbcp class will try execute that query when a getConnection()called, so that might produce the exception
Yes, it tries to execute it. But it should not throw an exception when it tries to hand you a bad connection. In stead, it tries to fix the connection. Maybe your database is not reachable when you try to get your connection. In that case, your connection pool won't be able to get a fresh connection for you. Why don't you show us your exception?
|
 |
karthic panneer
Ranch Hand
Joined: Sep 22, 2008
Posts: 57
|
|
Thanks for your reply When there is network failure i got exception. What i want is if the dbcp can't create connection pool then it should return null value or something instead of just throwing exception. Why i don't show stacktrace is that i know why the error occurs, it because of n/w failure only(ie purposly i disable the n/w connection). Why i am doing this means, this web application is going to deployed in client place. Before that i should know what are all the exceptions possible and tried to solve it that is other than getting exception. There is no way i think other than catching exceptions and handling the failure. Thankyou very much for your suggestions Karthic
|
 |
Jan Cumps
Bartender
Joined: Dec 20, 2006
Posts: 2343
|
|
What i want is if the dbcp can't create connection pool then it should return null value or something instead of just throwing exception.
It doesn't work that way.
There is no way i think other than catching exceptions and handling the failure.
That is how we usually handle database problems, with or without connection pooling.
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26144
|
|
Originally posted by karthic panneer: and tried to solve it that is other than getting exception.
The thing is - what solution is there. The best you can do is catch the exception and output a message to the client to check their network connection.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
karthic panneer
Ranch Hand
Joined: Sep 22, 2008
Posts: 57
|
|
Thanks very much for all. Finally i am using the exception handling. Thanks karthic
|
 |
 |
I agree. Here's the link: jrebel
|
|
subject: Checking connection status
|
|
|