import javax.servlet.jsp.jstl.sql.Result; import javax.servlet.jsp.jstl.sql.ResultSupport; ... ResultSet rs = ...; Result result = ResultSupport.toResult(rs); request.setAttribute("result", result); ...
Here's the javap on Result:
interface javax.servlet.jsp.jstl.sql.Result{ public abstract java.util.SortedMap[] getRows(); public abstract java.lang.Object[][] getRowsByIndex(); public abstract java.lang.String[] getColumnNames(); public abstract int getRowCount(); public abstract boolean isLimitedByMaxRows(); }
You can find more details in the JSTL spec in the SQL Actions section.
Matt Raible wrote:
Dear Struts Experts,
I recently started a new project where most of the backend code is already written with JDBC and ResultSets. The ResultSets are iterated through and a POJOs values are set using pojo.setName(rs.getString("...")), etc. - you get the point. I'm wondering if there's an easier way - so I could do something like this:
ResultSet rs = stmt.executeQuery("SELECT ..."); List objects = FancyUtilitity.convertResultSetToListOfObjects(rs, object.class);
Hibernate let me do this very simply - and I miss the fact that I could type
a line or two to get a List of POJOs.
List users = ses.createQuery("from u in class " + User.class + "order by u.name").list();
I've looked at the RowSetDynaClass (http://tinyurl.com/mekh), which has an interesting way of doing this - is this the "recommended" approach in the JDBC world? Here's an example using it:
ResultSet rs = stmt.executeQuery("SELECT ..."); RowSetDynaClass rsdc = new RowSetDynaClass(rs); rs.close(); stmt.close(); ...; // Return connection to pool List rows = rsdc.getRows(); ...; // Process the rows as desired
Thanks,
Matt
-- Kris Schneider <mailto:[EMAIL PROTECTED]> D.O.Tech <http://www.dotech.com/>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]