title: Bind parameters for ORDER BY in NamedParameterJDBCTemplate
body: <p>I am trying to use NamedParameterJdbTemplate in a Spring MVC application. The issue is that the bind parameters do not seem to work (no sorting happens) when I include one of ORDER BY clauses listed below. However, a hard coded order by column name in the sql works.</p>
  
  <pre><code>ORDER BY column1 
  ORDER BY column1 
  ORDER BY column1 asc
  ORDER BY column1 desc
  </code></pre>
  
  <p>For example, the below listed query does not work.</p>
  
  <pre><code>    private static final String SEARCH_ALL_BY_SORT_ORDER=
          " select FIRST_NM, MIDDLE_NM, LAST_NM, CUSTOMER_IDENTIFIER,  EMAIL_ADDRESS,  ACCOUNT_ID" +
          " from VIEW " +
          " where CUSTOMER_IDENTIFIER= :customerIdentifier " +
          " and ( REGEXP_LIKE(FIRST_NM, :firstName, 'i') " +
          "       or REGEXP_LIKE(LAST_NM, :lastName, 'i')  " +
          "       or REGEXP_LIKE(EMAIL_ADDRESS, :emailAddress, 'i')  )" +
          " order by :sortColumns";
  </code></pre>
  
  <p>The same query with a hard coded order by column works:</p>
  
  <pre><code>    private static final String SEARCH_ALL_BY_SORT_ORDER=
          " select FIRST_NM, MIDDLE_NM, LAST_NM, CUSTOMER_IDENTIFIER,  EMAIL_ADDRESS,  ACCOUNT_ID" +
          " from VIEW " +
          " where CUSTOMER_IDENTIFIER= :customerIdentifier " +
          " and ( REGEXP_LIKE(FIRST_NM, :firstName, 'i') " +
          "       or REGEXP_LIKE(LAST_NM, :lastName, 'i')  " +
          "       or REGEXP_LIKE(EMAIL_ADDRESS, :emailAddress, 'i')  )" +
          " order by LAST_NM";
  </code></pre>
  
  <p>Here's the relevant jdbctemplate code</p>
  
  <pre><code>Map &lt;String, Object&gt; params = new HashMap &lt;String, Object&gt;();
          params.put("customerIdentifier", customerIdentifier);
          params.put("firstName",  searchCriteria );
          params.put("lastName", searchCriteria );
          params.put("emailAddress",searchCriteria);
             // sortBy is COLUMN name
             // sortOrder is either 'asc' or 'desc'
          params.put("sortColumns", sortBy + " " + sortOrder);
             // Using just the column name does not work either
             //params.put("sortColumns", sortBy);
  
          namedParameterJdbcTemplate.query(SEARCH_ALL_BY_SORT_ORDER, params, new MemberMapper());
  </code></pre>