JaumeG wrote:
Hi all,
I'm doing a Database COnsole that results in DisplatTags COlumns.
I have a problem because I dont have setters and Getters methods for the
ResultQuery because The Results ara Variable depending on The Query
Executed.
I would like to know how to solve this problem.
I put my code.
Thanks in advance.
int i = 0;
try {
Statement stmt = con.createStatement();
stmt.setMaxRows(numeroMaxRegistros); // limited to 20000
ResultSet rs = stmt.executeQuery("select * from pers");
ResultSetMetaData rsmd = rs.getMetaData();
int cols = rsmd.getColumnCount();
ArrayList ar = new ArrayList();
int j = 0;
while (rs.next() && i++<numeroMaxRegistros) {
String[] elementos = new String[cols];
for (j = 1; j <= cols; j++) {
elementos[j-1]=rs.getString(j);
}
ar.add(elementos);
}
request.setAttribute("array",ar); %>
<display:table name="array" requestURI="sqlconsAction.do?accion=sort"
pagesize="10" defaultsort="1" defaultorder="ascending" >
<display:setProperty name="paging.banner.group_size" value="8"/>
<display:setProperty name="paging.banner.item_name">
</display:setProperty>
<display:setProperty name="paging.banner.items_name">
</display:setProperty>
<display:setProperty name="paging.banner.no_items_found">
</br></display:setProperty>
<display:setProperty name="paging.banner.one_item_found">
</br></display:setProperty>
</display:table>
<%
rs.close();
stmt.close();
con.close();
Instead of copying the row of data into an array why not put it into a Map:
ResultSetMetaData meta = rs.getMetaData();
while (rs.next() && i++ < numeroMaxRegistros) {
Map elementos = new HashMap();
for (j = 1; j <= cols; j++) {
elementos.put(meta.getColumnName(j), rs.getString(j));
}
ar.add(elementos);
}
DisplayTag can then use the Map to automatically generate the Columns.
Ed!
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
displaytag-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/displaytag-user