Don't perform basic SQL tasks in code

Relational databases are a mature technology, and they should be used to do as much simple work as possible.

For example, don't do the following in code, if they can be done in SQL instead:

Any corresponding task implemented by your own code would very likely: To retain the order of a ResultSet as specified in ORDER BY, choose a collection which has a defined iteration order, such as an ArrayList or a LinkedHashMap.

See Also :
Implementing compareTo
Choosing the right Collection
Reduce database code duplication
Implement code tables