Announcement Announcement Module
Collapse
No announcement yet.
queryForList Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • queryForList

    Hi all,

    I am using Spring 2.5.

    I am using JDBCTemplate and a prepared statement that uses LIKE operator for a string type column. I do not get any data back though it is a valid sql and there is data in the database. I do not have any issue with number type columns.

    I am using org.apache.commons.dbcp.BasicDataSource.

    Any help is highly appreciated.

    Thanks in advance.

    Code:
    String name = "Joe";
    int nbr = 4;
    
    idsList = ( List<String> )idJdbcTemplate.queryForList( "select id from x where name like ? and deptid = ?", new Object[] { name, new Integer(nbr) }, String.class );

  • #2
    Try this: Turn on debug logging and grab the logged statement. Insert it into a database client, replace the parameters and see whether it works there.

    There might be several reasons why it does not work. Maybe the parameterization is case-sensitive (is it perhaps 'joe' in the db?).
    It is also possible that the database contents are padded. So you might end up comparing 'Joe' with, say, ' Joe ', which is not equal.
    You may try 'Joe%' as parameter and see whether this will yield a result.

    Hope that helps,
    Andreas

    Comment


    • #3
      My bad. I by mistake did not inform in my original post that I am passing name value as 'JOE%'.

      The database has this value as JOEY (uppercase) and has no padding.

      Thus it is not working with the above. Hope to know the input.

      Sorry for any confusion caused.

      Comment


      • #4
        Does the query work if you enter it in a database client?

        Regards,
        Andreas

        Comment

        Working...
        X