• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

List Sorting

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Listen. That's my theme music. That's how I know I'm a super hero. That, and this tiny ad told me:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic