• Post Reply Bookmark Topic Watch Topic
  • New Topic

List Sorting  RSS feed

 
Richard Mendoza
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have an sql that retrieves data from three different tables. One parent table and 2 children tables. One record in the parent may have many records in the children. The result set has six columns (Id, Date, BeginTime, EndTime, Location). The query was sorted by the primary key of the parent table and I need it that way, I need to group all same records. Eventually I stored the resultset in a List. How do I sort the contents of the list by date, begin time and end time?
 
Reza Rav.
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should clarify how exactly you want to store them, by begin date, end date
duration ???
You can set it on your SQL query OR when you retrive them you can store them with some sort algorithm base on which column you want then store the sorted result in your List.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ideally you would not sort the ResultSet in a List, you would convert them to a Java representation (orbject-relational mapping tools arte excellent for this), then sorting is as easy as using the java.util.Collections sort() method. I should also point out that that you should make your java class implement Comparable to provide a natural ordering, or you can create a Comparator, or you can do both.

Another all-database solution would be to perform the same search again and return the primary keys only, sorted as desired and then match the ordering with the previous results, but personally I think this sounds like a terrible idea
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!