wood burning stoves
The moose likes JDBC and Relational Databases and the fly likes CachedRowSet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "CachedRowSet" Watch "CachedRowSet" New topic
Author

CachedRowSet

Richard Mendoza
Ranch Hand

Joined: Feb 26, 2003
Posts: 48
I'm using a cachedrowset to store data from the database... I wanted to sort the data in the cachedrowset by a particular field. Say I have queried the data resulting to 10 columns and eventually stored in a cachedrowset. I wanted to sort it for example by column 1 or column 3 or any column without reconnecting again to the database.
How am I going to do that?



Thanks,


Richard
damien malone
Ranch Hand

Joined: May 06, 2003
Posts: 35
I think you will have to parse out the results into memory, either into VO's that corresponds to the objects being brought back, or maybe even something as simple as a arraylists, a new instance for each row. You can then run a sorting algorithm on these, and store in something like a sorted list.

Damien
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 32614
    
215

I agree that it is good to use an ArrayList of value objects (beans with get and set methods.) Also, keep in mind that Java has a sort method. So all you have to do is write a Comparator that sorts on the correct field number and call Collections.sort(). It's much easier than writing your own sort algorithm.


[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: CachedRowSet
 
It's not a secret anymore!