?
Solved

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

Posted on 2007-10-01
6
Medium Priority
?
169 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.
0
Comment
Question by:rnicholus
  • 3
  • 2
6 Comments
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 19992067
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
0
 

Author Comment

by:rnicholus
ID: 19993408
Could you please tell me the reason why you say application scope is the best?
0
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 19993457
You end up creating less number of connections with database.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:rnicholus
ID: 19994537
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?
------------------------------------------------------------------

0
 
LVL 19

Accepted Solution

by:
Kuldeepchaturvedi earned 600 total points
ID: 19994785
First of all, having connections live in session is not a good idea, secondly having a live connection sitting overnite is not a good idea either..

The best way to connect to the database is to use container managed connection pools. Search for JDBC connection pool & you will get information about it.

Now if your application NEEDs to be continued logged on even after overnite of inactivity then you will have to change some time out settings around your application for it.

I suggest you start with reading up connection pooling a bit and we can take it from there.
0
 
LVL 23

Assisted Solution

by:Ajay-Singh
Ajay-Singh earned 450 total points
ID: 19995894
which connection pool are you using?
Look at this on how to configure the pool
http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
Tech giants such as Amazon and Google have sold Alexa and Echo to such an extent that they have become household names. And soon they are expected to be used by commoners in their homes, ordering takeout, picking out a song, answering trivia questio…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month17 days, 9 hours left to enroll

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question