struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Miguel Angel Mulero Martinez <>
Subject RE: Database Connection in Logic Beans - pooling?
Date Mon, 02 Sep 2002 06:34:49 GMT
You can too use the DBCP from jakarta, I'm using it and works perfectly:

-----Mensaje original-----
De: Steve McLeod []
Enviado el: lunes, 02 de septiembre de 2002 2:10
Para: ''
Asunto: Database Connection in Logic Beans - pooling?

I am using:
Tomcat 4.0
Struts 1.0.2

The problem

I have successfully used the Struts database connection pooling in a
web app, but as far as I can tell, a reference to the datasource can
only be
obtained from within an Action class (or directly within a JSP page but
let's not think about that today).

However I would like to have logic beans which handle database access,
rather than have this in the Action class. But I can't get a reference
the datasource from the logic bean because it doesn't have a
to which I can get a handle.

I have toyed with various ideas:
- Initialise a logic bean by passing it a reference to the Servlet
- Acquire a connection in the Action class and pass that to the bean

But really, I would rather the logic bean know inherently how to acquire
database connection.

My current workaround is to not use the Struts connection pooling, and
rather to manually create a connection each time database access needs
to be
done, then destroy it. But this is clearly not suitable for our

The context of my problem

I want to use some code like this in a JSP:

<jsp:useBean id="abean" scope="page"
class="" />
<table border="1">
<logic:iterate id="clientList" name="abean" property="clients"
        <td><bean:write name="clientList" property="clientID"/></td>
        <td><bean:write name="clientList" property="clientName"/></td>
        <td><bean:write name="clientList" property="active"/></td>

The idea is that ClientManager is used to handle all general database
for the Client bean (which maps to a Client entity in the database).
ClientManager.getClients() connects to the database, creates an
ArrayList of
Client objects, one for each row in the database, and returns the

ClientManager has other methods, such as:
-         ClientManager.delete(Client c), which deletes the row in the
database entity corresponding to the specified client.
-         ClientManager.findByPrimaryKey(int ID) which returns the
which matches the specified ID
- c), which stores the client in the
database, creating or updating as necessary

So an Action class can also call any of these directly, and it really
shouldn't care about how these work and how they store to/retrieve from
database. But I can't think of the elegant way to do this and still be
to use the Struts connection pooling.

Any thoughts?


Steve McLeod

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message