As it happens, though, I just checked in a change in commons-beanutils
that can be used for this purpose, if you're using Struts 1.1.
Basically, there's now a really simple way to copy the contents of a
ResultSet into a list of DynaBeans. This really is a *copy* operation,
so you have to pay some performance and memory cost, but it lets you
pass the data without having to create custom beans, and without leaving
the ResultSet open.
You'll need to grab a very recent nightly build of commons-beanutils
from:
http://jakarta.apache.org/builds/jakarta-commons/nightly/commons-beanuti
ls
and replace your commons-beanutils.jar file if you want to try this.
> Please include the .java and .jsp code.
>
In your Java code, you'd do something like this:
Connection conn = ...; // Get connection from the pool
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select custid, name from
customers");
RowSetDynaClass rsdc = new RowSetDynaClass(rs);
rs.close();
stmt.close();
... return connection to the pool ...
request.setAttribute("custoemrs", rsdc.getRows());
In your JSP page, treat this List of DynaBeans like you would any other
collection of beans, because all the Struts tags know how to deal with
DynaBeans.
See the updated Javadocs for commons-beanutils (included in the binary
distribution) for class org.apache.commons.beanutils.RowSetDataSource
for more information about this class.