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
NamedParameterJdbcTemplatebut are not using names in your query. You should have something like this.or don't use
NamedParameterJdbcTemplatebut just a regularJdbcTemplate.or, if the list of ids isn't too large use
NamedParameterJdbcTemplatewith anINclause instead of a batch update.