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?
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.
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: