aspose file tools*
The moose likes JDBC and the fly likes temporary Connection or connection pool? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "temporary Connection or connection pool?" Watch "temporary Connection or connection pool?" New topic
Author

temporary Connection or connection pool?

Bigwood Liu
Ranch Hand

Joined: Feb 26, 2003
Posts: 240
in a DAO, we keep a connection open through out an instance or we only get a
connection and close it in a data access method? Thanks.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30762
    
156

Damu,
If there is more than user user, a connection pool is usually best.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Bigwood Liu
Ranch Hand

Joined: Feb 26, 2003
Posts: 240
thanks,Jeanne.

Say, in a web application (no EJB layer), for MVC model, the controller(filter or servlet) will delegate the requests to corresponding model, and the model will do the business, like getting the date from database, then, my question is:

Where should we keep the connection pool? in controller or in model.

If we keep the connection pool in controller, I think it might be easy to manage all the connection in one class(not sure). but we have to pass the connection reference to the model. this seems violating the isolation.
[ March 20, 2007: Message edited by: damu liu ]
Daniel Dalton
Ranch Hand

Joined: Mar 20, 2005
Posts: 146
most servers will actually support connection pooling themselves. You should look into your particular servers details to find out how it is set up. Your web app would then access a connection via a JNDI lookup. Certainly you can do this in the Sun One webserver. I'm 99.9% certain that you can do it in tomcat by fiddling with the xml config files - though I've never done it.

Hope that helps,
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30762
    
156

Originally posted by damu liu:
Where should we keep the connection pool? in controller or in model.

Neither. You should keep it in the connection pool. If you server supports datasources, the server takes care of it as Daniel described. If not, you can use an open source connection pool like DBCP.

Either way, you request the connection from the pool in your data access code. It goes where you would have asked DriverManager for a connection if you weren't using pooling - in your data access class. While the connection pool is called from your model, technically it isn't in your model. And it certainly isn't in the controller - the controller should just be delegating requests.
Bigwood Liu
Ranch Hand

Joined: Feb 26, 2003
Posts: 240
thanks Daniel and Jeanne.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: temporary Connection or connection pool?