• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

forEach with a resultSet ?

 
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Can anyone tell me how to use the JSTL tag c:forEach with a resultSet which is generated in a bean, NOT with the <sql:query tag.

I get a "Don't know how to iterate over supplied "items" in <forEach>" exception when just using the resultSet from the bean.

Thanks.

Dave.
 
Sheriff
Posts: 67748
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't. And that's on purpose since that's not a very good practice. Result sets are tied to database connections which are resources that should be freed as soon as possible. The customary approach is to fetch the data from the result set at the lowest level possible (most definitely not within the JSP) and use it to populate EL-friendly structures (Collections, Maps and Beans) that are subsequently passed to the JSP page for display.

Since you are using the JSTL you should be aware that it is most effective when used in a Model 2 environment -- one in which processing takes place in servlet controllers, while JSPs are used solely for the purpose of generating the display.
[ March 20, 2005: Message edited by: Bear Bibeault ]
 
Dave Brown
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm I see, thanks Bear. I think I need to do a bit more reading on Maps/Arraylists etc to see what would be most appropriate.

It seems a bean is ideal to access a single record or to call methods of the bean straight from the jsp, but any tabular data is a bit trickier.

Thanks also for your contributions to my other questions.
 
Bear Bibeault
Sheriff
Posts: 67748
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you're showing just a table of data, sometimes nothing beats good old Object[][].
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic