Meaningless Drivel is fun!*
The moose likes JDBC and the fly likes Result Set Sorting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Result Set Sorting" Watch "Result Set Sorting" New topic
Author

Result Set Sorting

RAJEEV BAHL
Greenhorn

Joined: Apr 26, 2001
Posts: 15
I had gone through documentation on Result set and unable to find the way to sort Result Set. If I get a Result Set from Tabel with Primary Key in MS Access will I get Result Set Sorted on Primary Key ascending order?
Daniel Dunleavy
Ranch Hand

Joined: Mar 13, 2001
Posts: 276
Why are you not doing an order by in your select statement?
Dan
Brian Boyd
Greenhorn

Joined: Jul 23, 2001
Posts: 2
I also am interested in a solution to this problem.
"Why are you not doing an order by in your select statement?"
I do order the result set in the select statement. But I need to reorder the result set on a different column after processing the result set.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Normally, I create a 2D vector as resultset representation.
Then do the necessary order by as per the user input. Say intial order by was with Date, user asked by Name, manipulate the vector to do the order.
Hope this gives some input!
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

Originally posted by Brian Boyd:
I also am interested in a solution to this problem.
"Why are you not doing an order by in your select statement?"
I do order the result set in the select statement. But I need to reorder the result set on a different column after processing the result set.

After moving the result set values to an array or vector, then sorting, it seems like it would be faster and easier just to requery the database a second time and sort the ResultSet in the order that you need.
Jamie

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Every database connection is much costlier than a in-memory vector sorting. Literature says almost 50 times.
RAJEEV BAHL
Greenhorn

Joined: Apr 26, 2001
Posts: 15
Database connection can be maintained for group of calls ie till one call closeConnection.
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

gadzooks! That's crazy talk. If I had to make a connection for every query I made, I'd still be waiting for my fall 2000 audit to finish! I wasn't expecting you to reconnect after every query!
Assumption: One connection per session or thereabouts.
Jamie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Result Set Sorting
 
Similar Threads
Special Association Mapping in Hibernate
how to make data retrieval / query faster
com.mysql.jdbc.NotUpdatable: Result Set not updatable
Finding primary key
Getting primary keys