8

Am using NamedParameterJdbcTemplate for where Clause elements and one of them seems to be List<String>. JdbcTemplate replaces them ?,?,?...(list size) but for a IN clause with List<String> it has to be '?','?'....

Is there a way around this?

Gray
  • 115,027
  • 24
  • 293
  • 354
SriHarish
  • 311
  • 1
  • 4
  • 12

1 Answers1

10

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<String> nameRecordIDs = new ArrayList<String>(); 
// ...
// add values to collection, then
// ...
Map namedParameters = Collections.singletonMap("listOfValues", nameRecordIDs);
namedparameterJdbcTemplate.query(query, namedParameters,new MyMapper());
Community
  • 1
  • 1
Yogesh Chawla
  • 1,583
  • 18
  • 16