java - Spring NamedParameterJdbcTemplate delete with IN clause -



java - Spring NamedParameterJdbcTemplate delete with IN clause -

when seek execute delete, items set list<string>, namedparameterjdbctemplate seems not setting values placeholders of generated statement.

public class dbtest { public static void main(string[] args) { basicdatasource basicdatasource = new basicdatasource(); basicdatasource.setdriverclassname("com.mysql.jdbc.driver"); basicdatasource.seturl("jdbc:mysql://localhost:3306/test?rewritebatchedstatements=true"); basicdatasource.setusername("root"); basicdatasource.setpassword("qwedsa"); namedparameterjdbctemplate template = new namedparameterjdbctemplate(new jdbctemplate(basicdatasource)); immutablemap<string, ?> param = immutablemap.of("items", newarraylist("a", "b", "c"), "user_id", 1); map<string, ?>[] params = new map[]{param}; template.batchupdate("delete sample col1 in (:items) , user_id = :user_id", params); } }

error

bad sql grammar [delete sample col1 in (?, ?, ?) , user_id = ?]; nested exception java.sql.sqlexception: no value specified parameter 3

doesn't namedparameterjdbctemplate expand lists delete statements?

you can simplify code to:

public static void main(string[] args) { basicdatasource basicdatasource = new basicdatasource(); basicdatasource.setdriverclassname("com.mysql.jdbc.driver"); basicdatasource.seturl("jdbc:mysql://localhost:3306/test?rewritebatchedstatements=true"); basicdatasource.setusername("root"); basicdatasource.setpassword("qwedsa"); namedparameterjdbctemplate template = new namedparameterjdbctemplate(basicdatasource); immutablemap<string, ?> param = immutablemap.of("items", newarraylist("a", "b", "c"), "user_id", 1); template.update("delete sample col1 in (:items) , user_id = :user_id", param); }

which works fine

java spring jdbc jdbctemplate

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -