Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Rudy Rusli
Ranch Hand
Posts: 114
  • 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: 64623
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
  • 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: 64623
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic