• 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

Are ResultSets Thread Safe?

 
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was having some errors in a JSP page where I am processing a ResultSet. The error was that the ResultSet operation was invalid after the ResultSet was closed. Huh?
The ResultSet processing was in a JSP page that had a meta-refresh and lots of clients.
I've since moved the ResultSet to a class and just return a String to the JSP, but am still wondering what was going on.
Any advice would be appreciated.
Thanks.
-- Mike
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mike,
Once the result set, statement or connection objects have their close() methods called, you cannot access the result set anymore. Your second solution is safer because it returns the db resources sooner.
 
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ResultSets are not thread safe and by default they can only be looped through once. Scrollable ResultSets and CachedRowSets can be looped through more than once though. Also ResultSets are not serializable (so can't be returned from EJBs).
Check out the FormattedDataSet for an easy way to convert ResultSets to HTML or XML or any other text. The FormattedDataSet can also convert ResultSets to Object[][]. Obviously 2 dim arrays can be looped through any number of times.
See http://www.fdsapi.com for a live demo of converting tabular data including SQL and 2 dim arrays to XML, HTML (including tables, list boxes, drop down list boxes,...), and CSV.
 
Mike London
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Steve!
-- Mike
 
This cake looks terrible, but it tastes great! Now take a bite out of this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic