File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Rudy Rusli
Ranch Hand
Posts: 114
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rudy Rusli
Ranch Hand
Posts: 114
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I'm using Tomcat. What do you mean by 'container-managed connection pooling'?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tomcat provides a connection pooling mechanism (DBCP). Search this forum for previous discussions on setup.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic