File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Application persistence across database shutdown/startup Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Application persistence across database shutdown/startup" Watch "Application persistence across database shutdown/startup" New topic
Author

Application persistence across database shutdown/startup

Ninad Kuchekar
Ranch Hand

Joined: Jan 05, 2010
Posts: 64
Hi,

I have an application and I am using a customized framework, which is similar to Struts + Hibernate. The problem I am facing is that, suppose an user is using the application and if the database shuts down, the user gets an error page saying "Runtime Error"(This page is already configured by my application ). Now I don't want the user to get this page in case the database is "up" and running again. In short, I want to refresh all the stale connections(from the Connection Pool) and let the user start afresh without any error page.

I am using Oracle 10g

FYI: I have already tried OracleConnectionCacheManager's refreshCache(cacheName, mode) method and it doesn't work, for me atleast.


The method I have used for getting a connection is below:


Don't walk as if you rule the world, walk as if you don't care who rules it...
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2476
    
    7

Does your connection pool support validationQuery?


OCUP UML fundamental and ITIL foundation
youtube channel
Ninad Kuchekar
Ranch Hand

Joined: Jan 05, 2010
Posts: 64
Hi Jan,

Thanks for your response. No I am not using any validation query. I thought it might hamper the performance a bit. Is it so? I am not completely aware of the consequences and also not sure how exactly does a validationQuery work .
What do you suggest? Any other options are also welcome.
Thanks again!
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2476
    
    7

you have to choose a very cheap query that returns at least one row, like "select 1 from dual".
This query is executed every time you ask a connection from the pool.
If the query does not return at least one row (that means: something is wrong) the pool discards the bad connection, and creates a brand new connection.

This mechanism is not very expensive, and helps you a lot.
No I am not using any validation query. I thought it might hamper the performance a bit.

My advise is: don't just assume that something is bad for performance.
Ninad Kuchekar
Ranch Hand

Joined: Jan 05, 2010
Posts: 64
Thanks again Jan!!...
Could you help with using it? How do I configure it? I searched for "validationQuery" configuration, but found little help.
I am using JBoss 4

P.S.: Thanks for the advice too, I'll keep that in mind.
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2476
    
    7

from http://community.jboss.org/wiki/configdatasources



  • <check-valid-connection-sql> - an sql statement that is executed before it is checked out from the pool to make sure it is still valid. If the sql fails, the connection is closed and new ones created.
  • Ninad Kuchekar
    Ranch Hand

    Joined: Jan 05, 2010
    Posts: 64
    Thanks for nth time Jan...that one should resolve it.
     
    Don't get me started about those stupid light bulbs.
     
    subject: Application persistence across database shutdown/startup
     
    Similar Threads
    Using a jsf DAO interface
    Connection pooling with my own cofiguration file instead of Initial Context.
    Newbie having problems with StrutsMocktestCase
    ThreadLocal and DB connection...
    jsf and database connection problem