File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Q on cached datasource Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Q on cached datasource" Watch "Q on cached datasource" New topic

Q on cached datasource

Neel Krish

Joined: Mar 26, 2001
Posts: 8
We are on WAS3.5. We are caching the datasource at a particular initialization point and from there on this same datasource is being used for all further database connections.
Lets assume that at some point in time, the database goes down. Obviosuly the datasource will not be able to get any connections and will keep throwing SQLExceptions. Now when the database is re-started, what will happen to the cachedDatasource.getConnection()? Will this continue to fail? Or will it start getting connections?
I thought it would continue to fail unless this cached datasource is "refreshed" .
Help me understand.
Philip Shanks
Ranch Hand

Joined: Oct 15, 2002
Posts: 189
Can you test it by dropping your app server's network interface to simulate the database crash?

Philip Shanks, SCJP - Castro Valley, CA
My boss never outsources or has lay-offs, and He's always hiring. I work for Jesus! Prepare your resume!
Neel Krish

Joined: Mar 26, 2001
Posts: 8
well i won't be able to do that since we share our server with quite a few applications.
but as my luck would have it, couple of days back the database crashed. the first getConnection() call failed with a SQLException of a "communication protocol error". and it never recovered. the database was down for about 15 mnts. we recycled our app instance and everything started working fine.
one observation - i have a single standalone page which basically is like monitor. it checks whether all the components/interfaces/connections are working fine. it is a single stop for us to determine what is failing. interstingly, i loaded this page when the database was down and as expected i got the connection exception. but on a refresh after a few minutes, it was able to establish a connection successfully. the only difference between this and the application code is, i do not use the cached datasource. datasource is obtained through a jndi lookup everytime this page is loaded.
this makes me wonder whether i should nullify the cached datasource and re-lookup whenever a db crash related connexion failure occurs.
I agree. Here's the link:
subject: Q on cached datasource
It's not a secret anymore!