This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Checking connection status

 
karthic panneer
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 88
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jan Cumps
Bartender
Posts: 2576
11
C++ Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
karthic panneer
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2576
11
C++ Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2576
11
C++ Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 33694
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
karthic panneer
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much for all.

Finally i am using the exception handling.




Thanks
karthic
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic