aspose file tools*
The moose likes Struts and the fly likes Struts Database Connections Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts Database Connections" Watch "Struts Database Connections" New topic
Author

Struts Database Connections

Tad Dicks
Ranch Hand

Joined: Nov 16, 2004
Posts: 264
I'm working on a project using a Mysql database as the back end. My partner and I are wondering how best to handle the connections to the database.
We have a class that handles creating objects populated with values from the database, and would also take objects to write them to the database.

We seem to have a disagreement about how to deal with the actual connection. She thinks we should do something like:

Where as I think inside of each method in the DBAO file
we should use con=dataSource.getConnection; do stuff...; con.close();

We both think we should keep a copy of the DBAO object in the application or session. I'm just concerend about how and when the remove function would get called, that if it never got called the connection wouldn't be closed and would cause problems. She's concerned that opening and closing the connection too many times will cause performance problems.

Who is right?

-Tad
Nandkishore Dhilde
Greenhorn

Joined: May 09, 2002
Posts: 20
why dont you use connection pooling. creat some connections cache it in HashMap and reuse it using JDCConnectionPool.java it will return available connection and if not available it will creat one
go through for more detail..



web page


SCJP1.4 certified, IBM SOA Solution Designer[2007]
Tad Dicks
Ranch Hand

Joined: Nov 16, 2004
Posts: 264
Doesn't or whatever JSP container create a dbcp for you? and when you create the connection from the datasource isn't this coming from the dbcp?

Or am I missing something else here that is fundamental?


-Tad
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by Tad Dicks:
Doesn't or whatever JSP container create a dbcp for you? and when you create the connection from the datasource isn't this coming from the dbcp?
Yes, in practice when you get a hold of a DataSource object, it is strapped on top of a connection pool of some sort. However, there are cases where the said connection pool has been configured with a limit of maximum number of connections set to just 1


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Struts Database Connections