The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
July 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

ORDER BY PARAMETER

Posted by Tom on July 18, 2000 at 1:07 PM

Is it possible to sort a database with an HTML form to select the sort criteria passing a parameter to a servlet? The following code snippet from my servlet will not work with ? for ORDER BY: Do you have any suggestions?

String parameter = null;
if ((request.getParameter("SORT")) == null)
stmt = conn.prepareStatement("SELECT * FROM LIB.CUST" +
" ORDER BY cmgage "); // Execute the query
else {
parameter = request.getParameter("SORT");
stmt = conn.prepareStatement("SELECT * FROM LIB.CUST " +
" ORDER BY ? " ); // Execute the query
stmt.setString(1, parameter);

Tom



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us