aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Iterate through a ResultSet" Watch "Iterate through a ResultSet" New topic
Author

Iterate through a ResultSet

Ed Chawlik
Greenhorn

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 >

Error:


javax.servlet.ServletException: No getter method for property EMPNO of bean customer
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:846)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
org.apache.jsp.masterlist_jsp._jspService(masterlist_jsp.java:215)
...
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.


Merrill
Consultant, Sima Solutions
Ed Chawlik
Greenhorn

Joined: Aug 10, 2005
Posts: 16
Thank you guys, I will give that a try.
 
 
subject: Iterate through a ResultSet