This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes JDBC and the fly likes How to check if DB Connection is LOSTwhen using DATASOURCE Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to check if DB Connection is LOSTwhen using DATASOURCE" Watch "How to check if DB Connection is LOSTwhen using DATASOURCE" New topic
Author

How to check if DB Connection is LOSTwhen using DATASOURCE

Sunitha Mudidani
Greenhorn

Joined: Apr 25, 2006
Posts: 28
Hi we are using weblogic and oracle server
we are using datasource to obtain connections


The problem is when using a connection,(not getting the connection at the same point)
i will get an SQLException only even if the connection to the WLserver is lost or connection to the database is lost.

In each case i should try to reconnect to the appropriate server. But how do I get to know the source of SQLException ?

One option is checking the errorcode but,

1> is it not vendor dependent?
2> Is this approach correct or any other solution exists?? Point to those resources also, if yes

Pls respond with your valuable suggestions

Thanks
Sunitha Mudidani
Greenhorn

Joined: Apr 25, 2006
Posts: 28
Any suggestions pls!!
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3697
    
    5

Is it sort of vendor dependant although you could construct special cases that try to handle vendors and codes efficiency.

Generally though, I do not follow why you want to decode it. For starters, losing a database connection should be an exception, not the standard. Other than the database going offline, its not easy to lose access. Second, most design patterns encourage transactions. For example, if you lose your database connection halfway through a transaction the correct step is not to check for an active database connection and try to move on without it but to let the exception be thrown so that a transactional rollback is triggered, then recover after the transaction has been terminated.

Back to my original thought, is there a reason you're losing connections? Are you remembering to close them after they are used?


My Blog: Down Home Country Coding with Scott Selikoff
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to check if DB Connection is LOSTwhen using DATASOURCE
 
Similar Threads
Validating user/password for database connection
Questions Regarding Connection Pooling
Using datasource for login bean & login page?
Creating datasource and Closing connection?
Difference between DataSource and ConnectionPoolDataSource