Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Are ResultSets Thread Safe?

 
Mike London
Ranch Hand
Posts: 1290
6
  • Mark post as helpful
  • send pies
  • 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
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35753
412
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • 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
Ranch Hand
Posts: 1290
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Steve!
-- Mike
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!