JdbcTemplate IN Clause for String elements

后端 未结 1 1219
花落未央
花落未央 2021-01-05 10:58

Am using NamedParameterJdbcTemplate for where Clause elements and one of them seems to be List. JdbcTemplate replaces t

1条回答
  •  [愿得一人]
    2021-01-05 11:18

    There a few other similar questions out there which might have helpful answers for you:

    How to execute IN() SQL queries with Spring's JDBCTemplate effectivly?

    To make this style of query work on my end, I have to switch from plain old JDBCTemplate to NamedParameterJdbcTemplate.

    Here is some example code:

    String query = "select * from table where columnName in (:listOfValues)";
    List nameRecordIDs = new ArrayList(); 
    // ...
    // add values to collection, then
    // ...
    Map namedParameters = Collections.singletonMap("listOfValues", nameRecordIDs);
    namedparameterJdbcTemplate.query(query, namedParameters,new MyMapper());
    

    0 讨论(0)
提交回复
热议问题