4

This is an extension of How to execute IN() SQL queries with Spring's JDBCTemplate effectivly?

I wish to modify the query to be:

"SELECT * FROM foo WHERE name=? and value IN (:ids)"

how can I modify the given code to support the name=? parameter

Set<Integer> ids = ...;

MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("ids", ids);

List<Foo> foo = getJdbcTemplate().query("SELECT * FROM foo WHERE a IN (:ids)",
     getRowMapper(), parameters);
Community
  • 1
  • 1
Evilsithgirl
  • 339
  • 1
  • 7
  • 18

1 Answers1

1

I was successful using both comments.

I will post the code below for those who may find this question later:

String sql = "SELECT * FROM foo WHERE name=:name and value IN (:ids)";

Set<Integer> ids = ...;
String name = "John";

MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("ids", ids);
parameters.addValue("name",name);

List<Foo> foo = getNamedParameterJdbcTemplate().query(sql, parameters, getRowMapper());
Evilsithgirl
  • 339
  • 1
  • 7
  • 18