Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » J2EE Interest »

Re: sorting query results in J2EE

Ben Hill

2003-09-24

Replies:

Using ORDER BY is a reasonable method, as it means the DB is doing the
sorting. I have seen people use container located sorting methods, but
it does mean you have to cache the data outside of the DB which seems
slightly to suggest that the DB should be used.

Another method is to use something like a custom tag to render the VOs
results to the client. By passing in something like column headers then
you could get the tag to order the list.

Something like:

<utils:listRenderer sortColumn='<%= request.getParameter("sortColumn")
%>' />

Then your URL could be:

http://server/page.jsp?sortColumn=name

or:

http://server/page.jsp?sortColumn=age

Your custom tag would do the sorting, but it could just as easily
re-call the DB access method which uses the ORDER BY SQL method.

HTH

Cheers,

Ben


On Wed, 2003-09-24 at 13:55, Stan Ou wrote:
> Hi all,
>
> I have a sql query that joins 5 or 6 tables that
> returns 100 to 200 records. The result is wrapped in a
> VO and is rendered in a JSP by html table. the user
> can click one of the 4 column headings to sort the
> result. what is the best to achieve this ? thanks in
> advance.
>
> I've seen it being done this way:
> In the stored procedure, put the query in a string,
> like this:
> (pseudo code)
>  a.set @sqlString = "select blah blah ... order by "
> + @inParamSortOption
>  b. execute @sqlString
>
> this is the low tech way but gets the job done. But
> I'd like to see a better way.
>
> stan
--
mail: ben@(protected)
home: www.javacoder.net - "Java Coding, from the Source!"

===========================================================================
To unsubscribe, send email to listserv@(protected)
of the message "signoff J2EE-INTEREST". For general help, send email to
listserv@(protected)".


©2008 junlu.com - Jax Systems, LLC, U.S.A.