This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hello, I have seen a similar post to this one but did not see any answer.
From a JSP page, I run a method in a Java class to query a database and get a resultset. Back in the JSP I do a loop thru the RS and print every column there is in each row.
Every column can be sorted asc/desc by clicking the column heading. We do not want to access the database every time we click on a column to create again the RS sorted by the column chosen.
What I need is a way to sort the result set by the specific column either asc/desc ONCE CREATED. I have seen I could put the RS into a List and do Collections.sort() but if anybody can give me a real example of this I would really appreciate it.
Originally posted by Martin Moraga: However I did not ask to know if I had to use a ResultSet with a JSP or not.
JavaRanch is a learning site. So whether you ask for it or not, you are going to get recommendations regarding best practices. Most people learn by listening to those that have already made the mistakes and share their tales of how to avoid them.
Besides, it's part of the answer. Result sets are cranky, cantankerous beasts and you should copy the data out of them and send them on their way immediately.
Once you have the data in a more reasonable construct, it's a lot easier to do things like caching and sorting and other stuff. To include, accessing them in a reasonable manner in a JSP. [ September 29, 2008: Message edited by: Bear Bibeault ]
List<MyData> can be stored in HttpSession or any other relevant place. Now your JSP should display the data from List<MyData> and whenever required do the sorting on this List, never go back to database again.