I want update a column of table for bulk records. How can i do that using NamedParameterJdbcTemplate
List<Long> ids = new ArrayList();
ids.add(1);
ids.add(2);
String updateQuery = "update product set status = 'P' where id = ?";
SqlParameterSource batch = SqlParameterSourceUtils.createBatch(ids.toArray());
namedParameterJDBCTemplate.batchUpdate(updateQuery, batch)
However, the above is not working. Please advise
You are using
NamedParameterJdbcTemplate
but are not using names in your query. You should have something like this.or don't use
NamedParameterJdbcTemplate
but just a regularJdbcTemplate
.or, if the list of ids isn't too large use
NamedParameterJdbcTemplate
with anIN
clause instead of a batch update.