Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8294861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:22:36+00:00 2026-06-08T14:22:36+00:00

I am trying to use NamedParameterJdbTemplate in a Spring MVC application. The issue is

  • 0

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.

ORDER BY column1 
ORDER BY column1 
ORDER BY column1 asc
ORDER BY column1 desc

For example, the below listed query does not work.

    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";

The same query with a hard coded order by column works:

    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";

Here’s the relevant jdbctemplate code

Map <String, Object> params = new HashMap <String, Object>();
        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());
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T14:22:39+00:00Added an answer on June 8, 2026 at 2:22 pm

    Only values can be bound as parameters. Not parts of the query itself.

    In the end, a prepared statement is generated and the parameters are bound to the prepared statement. The principle of a prepared statement is to prepare the execution plan of the query (of which the order by clause is a part), and to execute the query one or several times after, with varying parameters.

    If the query is not complete, the execution plan can’t be prepared and reused. So, for this part of the query, you’ll need to generate the query dynamically using string concatenation, and not parameters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use @Transactional in a Spring MVC application to gain atomicity.
I am trying use gem tire to search in my application. I have tables
Trying to use this sql statement. The first 2 parts work fine, I am
trying to use the preferred on method call but the code is not working
I'm trying to use this class but I can't seem to figure out how
I'm trying use eco for client-side templating. I have multiple .eco templates that I'd
I have a regex that I'm trying use to validate against strings. Trying to
I have a 3rd party DLL that I am trying to use in a
I'm trying use double type in openCL, but doesn't work anyway, i want use
Trying to use Java's regexp I want to match /app, /app/.* , but not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.