I know this really is off topic, but with the discussion about user
authentication and PreparedStatements some two weeks ago in mind, I
thought maybe somebody here can answer a quiestion.

How do I use ORDER BY with PreparedStatement?

We use this in a web app where the user should be able to change sorting
in a "Windows Explorer"-like fashion.
The problem occurs when I want to use multiple sorting fields.

Example:
If I have
  preparedStatement = conn.prepareStatement("SELECT * FROM articles
ORDER BY ?");
then
  preparedStatement.setString(1, "articleId");
works fine but
  preparedStatement.setString(1, "articleText, articleId");
doesn't (which actually isn't very surprising).

I haven't tried
  conn.prepareStatement("SELECT * FROM articles ORDER BY ?, ?");
  preparedStatement.setString(1, "articleText");
  preparedStatement.setString(2, "articleId");
since it depends on what the user clicks how many fields we want in
there.

How do I solve this? Is it driver dependent?

  Mattias Jiderhamn
  Expert Systems
  [EMAIL PROTECTED]

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

Reply via email to