• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Smith Li
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I'm using Tomcat. What do you mean by 'container-managed connection pooling'?
 
reply
    Bookmark Topic Watch Topic
  • New Topic