This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes Process results from resultset vs from data structure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Process results from resultset vs from data structure" Watch "Process results from resultset vs from data structure" New topic

Process results from resultset vs from data structure

Mike Ottinger
Ranch Hand

Joined: Jan 11, 2002
Posts: 125
Hi Guys,

I'm working with a DB2 backend that returns, not an incredible amount of data, but somewhat sizable(100+ rows x 28 columns). The issue is the data needs to be processed in a pretty complex fashion. The initial design is to run through the resultset once and handle the processing that way. This lends towards an awkward design, as it's sometimes necessary to go back to previously processed rows to determine certain values. So the design gets ugly with loop variables and flags all over the place. And some columns from the call are used throughout every aspect of the processing, yet they're never taken off the resultset. I've decided to look into redesigning it so that the call is executed, the resultset is stored in a collection of beans, thus processing is more straight-forward, because the entire results are made available in an internal data structure. This collection will be iterated through a number of times, but I still feel this is a faster solution. What difference in performance can be gathered between a call to a resultset, versus a call to a getter in a bean, within a collection? Thanks, and sorry for the long-winded question


SCJP 1.4 SCJD 1.5
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
As you would want to close JDBC objects as soon as possible, it looks to me as if you need a disconnected RowSet. This means that the RowSet gets the data from the data source and its connection is then closed. You can then retrieve the data from the RowSet without tieing up connections and cursors.

SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
I've never seen the advantage of a disconnected row set versus a collection of beans, beyond the quick and dirty aspect of not needing to code the bean class (although you usually need to code it eventually in any case). Why go for the row set? I'm thinking POJO beans a la Hibernate here.

There is no emoticon for what I am feeling!
Mike Ottinger
Ranch Hand

Joined: Jan 11, 2002
Posts: 125
Hi Guys,

Thanks for the replies. I'm not familiar enough with Hibernate to know whether it would be a viable solution for what I'm working on. My data doesn't need to persist for too long. I read it in, generate a rather complicated xml structure off of it, then send it on its way through a JMS queue. I always imagined Hibernate as a persistence mechanism that employs POJO rather than db related stuff. I think I can gather from the replies that the idea of moving my data into a POJO structure is the better way to go(?). Thanks.
I agree. Here's the link:
subject: Process results from resultset vs from data structure
Similar Threads
Delay in JDBC ResultSet
Insert & Update
Resultset with million rows
ResultSet randomizing
Retrieve data from a table