DEVFYI - Developer Resource - FYI

I need to have result set on a page where the user can sort on the column headers. Any ideas?

JDBC Interview Questions and Answers


(Continued from previous question...)

I need to have result set on a page where the user can sort on the column headers. Any ideas?

One possibility: Have an optional field in your form or GET url called (appropriately) ORDER with a default value of either "no order" or whatever you want your default ordering to be (i.e. timestamp, username, whatever). When you get your request, see what the value of the ORDER element is. If it's null or blank, use the default. Use that value to build your SQL query, and display the results to the page. If you're caching data in your servlet, you can use the Collection framework to sort your data (see java.util.Collections) if you can get it into a List format. Then, you can create a Collator which can impose a total ordering on your results.

(Continued on next question...)

Other Interview Questions