File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Iterate through a ResultSet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Iterate through a ResultSet" Watch "Iterate through a ResultSet" New topic

Iterate through a ResultSet

Ed Chawlik

Joined: Aug 10, 2005
Posts: 16
I am fairly new to struts and am trying to interate though an Oracle result set; the SCOTT/TIGER emp table. I saw this on another forum, but cannot get it to work. If someone knows of a better way or how to get this to work, I am all ears:

Regards, ed

Java Action code (works fine)

stmt = conn.createStatement();
rset = stmt.executeQuery("SELECT EMPNO, ENAME FROM scott.emp");
rsdc = new RowSetDynaClass(rset);
request.setAttribute("customers", rsdc);

JASP code:

<logic:iterate id="customer" name="customers" property="rows" scope="request">
<br>This is filler text
<bean:write name="customer" property="EMPNO"/>  
<bean:write name="customer" property="ENAME"/>
</logic:iterate >


javax.servlet.ServletException: No getter method for property EMPNO of bean customer
Ergin Er
Ranch Hand

Joined: Sep 06, 2005
Posts: 60
Maybe you should convert the ResultSet to a List before you put it into session?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The trouble with this code is that your variable "customer" is of type DynaBean, and DynaBean is not a true javaBean. There is no getEMPNO() method but only a get(String) method. My suggestion would be to create an Employee bean. You could then create a list of Employee beans and use the BeanUtils.copyProperties() method to copy the properties of the DynaBean to the Employee bean.

Consultant, Sima Solutions
Ed Chawlik

Joined: Aug 10, 2005
Posts: 16
Thank you guys, I will give that a try.
I agree. Here's the link:
subject: Iterate through a ResultSet
It's not a secret anymore!