• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts and jdbc access...

 
Heath Lilley
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
We have recently decided to standardize on struts as our MVC web framework of choice. We have several apps with "home brewed" versions of the MVC framework. We don't use EJB's.
I am starting to understand STRUTS pretty well know and just have a question regarding JDBC.
In the older apps we implemented a connection factory class that was able to load the connection properties from a file and return a standard connection by calling an instance method or a static method. In the same method we would setup a sql statement and then execute the statement then close the connection. This was using Websphere's connection pooling.
Now with struts I realize that I would instantiate a connection either directly in the action class or in a support object that is declared/instantiated inside of the action class.
My question is does it make sense to create a "ConnectionFactory" class that gives you a standard connection and still open, execute, and close the object from within the same method?
OR
Create a wrapper class around a standard connection object and pass it around from one sql method to another sql method then return the connection object back to the method that originally opened it so that it can be closed?
OR
Another way that I am just not seeing.
I realize that there are probablly a couple dozen ways to setup jdbc I'm hoping to find a way that others have found it to work well in struts.
Thanks in advance.
Heath
 
Rohit Lal
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I wonder if this will help, but have you tried using the DAO (Data Access Object) pattern?
Suggest you read up this pattern and use a single DAO object in your Action class to perform all d/b queries and updates. You will be building the ConnectionFactories, etc. once, say, in an init() method and then using the execute method passing appropriate arguements to the execute() method to perform a particular prepared statement. At the end of the Action class, you can access, say the closeConnections() method of the DAO to perform clean up operations.
Related Patterns to read up are ServiceLocator, Factory, AbstractFactory & Value Object.
Also suggest you store your sql preparedstatement definitions (not dynamically built though) in an XML file along with a key identifier e.g.:
<sql-statements>
<criteria key="queryID1">
<body>

</criteria>
</sql-statements>
 
Rohit Lal
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I wonder if this will help, but have you tried using the DAO (Data Access Object) pattern?
Suggest you read up this pattern and use a single DAO object in your Action class to perform all d/b queries and updates. You will be building the ConnectionFactories, etc. once, say, in an init() method and then using the execute method passing appropriate arguements to the execute(..) method to perform a particular prepared statement. At the end of the Action class, you can access, say the closeConnections() method of the DAO to perform clean up operations.
Related Patterns to read up are ServiceLocator, Factory, AbstractFactory & Value Object.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic