Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What will be a good approach for sorting data extracted from DataBase.

 
PavanPL KalyanK
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Please give your suggestions .

I want to extract the records based on Employee First Name .

What will be a good approach ?


1. To write a SQL Query based on the order by clause

OR

2. Extract the elements into a TreeSet by using a Comparator .

Thanks in advance.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34672
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both are acceptable solutions. As to which is better - 'it depends.' If the SQL query is only run for this use, adding an order by is fine.
 
PavanPL KalyanK
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks .
 
pradeep dewda
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ofcourse it is fine and easy to use query..
Select * from table order by cluase ASC

We get the sorted values in ResultSet.
 
PavanPL KalyanK
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes you are right .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic