File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes Connection to the database in Web-Application (JSP apps.) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Connection to the database in Web-Application (JSP apps.)" Watch "Connection to the database in Web-Application (JSP apps.)" New topic
Author

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

Rudy Rusli
Ranch Hand

Joined: Jun 01, 2006
Posts: 114
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.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61206
    
  66

Originally posted by Rudy Rusli:
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?
None of the above. Maintaining connection information in the UI tier is a strongly discouraged practice. You should be using container-managed connection pooling. Are you using Tomcat?

2.) Currently I have a session-scope bean that maintains connections to the database. ... How should I handle this?
See above.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rudy Rusli
Ranch Hand

Joined: Jun 01, 2006
Posts: 114
Yes, I'm using Tomcat. What do you mean by 'container-managed connection pooling'?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61206
    
  66

Tomcat provides a connection pooling mechanism (DBCP). Search this forum for previous discussions on setup.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Connection to the database in Web-Application (JSP apps.)