Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts Database Connections

 
Tad Dicks
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Tad Dicks
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic