• Post Reply Bookmark Topic Watch Topic
  • New Topic

Keeping connection to a DB with Servlets JavaBeans  RSS feed

 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm using JSP in conjuction with JavaBeans and servlets in a very simple web application. The problem that I have is that I'm not quite sure where exactly I should create the connection to the database and keep it throughout a client session. Some people say that you should have a servlet that handles the connection and others say that I should create a JavaBean that knows about the database connection and will keep it alive until the end of the session.. any suggestions, I'd like to follow the MVC. thanks.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are talking about storing database resources on the session to re-use it just for that user, I think this is a very bad idea.
Placing database or system resources on the session can choke the system and can lose resources if they don't get cleaned up properly. I'd be looking at connection pooling rather than trying to explicitly maintain a connection.
Dave
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok thanks, I think I was understanding the connection from a very different (not logical, and weird) point of view... But, would you use a servlet to perform this operation or a JavaBean?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally? Neither.
JavaBeans are mostly a web-centric solution and I prefer a more generic solution, so DB operations happen in a separate module so they aren't specific to a particular solution.
I don't use EJBs either cos I find them a bit too heavy
Dave
 
kiran killedar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends upon your requirement i feel java beans is the best solution in jsp .
 
Ashok Talluri
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you can have the connection pool in the servlet context or a session with application scope. Any comments ??
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The pool should be stored in the Servlet Context. That is the only object shared by all users and all servlets.
Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!