• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Checking connection status

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks very much for all.

Finally i am using the exception handling.




Thanks
karthic
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic