We help IT Professionals succeed at work.

Connection to the database in Web-Application (JSP apps.)

rnicholus
rnicholus asked
on
199 Views
Last Modified: 2010-04-01
I have some questions regarding how you maintain connection to the database when building web applications.

1.) What's the best practice to maintain connection to the database to get data from it?
Is it request-scope, session-scope, or application-scope?

2.) Currently I have a session-scope bean that maintains connections to the database. The problem is if I open the browser overnight and the came back in the morning, I get some CommunicationsLinkFailure exception. I think this is because the session has died. How should I handle this?

Thanks in advance for all the help.
Comment
Watch Question

Best is: application scope. Or even better tomcat/web container global
connection pool. tomcat uses commons-dbcp which has automatic detection for
stale connections
 
http://commons.apache.org/dbcp/configuration.html

Author

Commented:
Could you please tell me the reason why you say application scope is the best?
You end up creating less number of connections with database.

Author

Commented:
I have tried having a bean with application-scope to maintain a connection to the database.
Then I went home and tried to open it at public computers.
It still gives me "communication links failure" error like what happen with #2 in my first post.

------------------------------------------------------------------
2.) Currently I have a session-scope bean that maintains connections to the database. The problem is if I open the browser overnight and the came back in the morning, I get some CommunicationsLinkFailure exception. I think this is because the session has died. How should I handle this?
------------------------------------------------------------------

Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.