Experimenting with Spring-JDBC. I am using this as reference. I am trying to get a list of actors who have the same last name. Running this code gave me the desired results:
Use IN Clause..
How to use SELECT IN clause in JDBCTemplates?
List<String> lastnames= new ArrayList<>();
Map namedParameters = Collections.singletonMap("lastnamevalues", lastnames);
StringBuffer recordQueryString = new StringBuffer();
recordQueryString.append("select FIRSTNAME, LASTNAME from ACTORS where lastname in (:lastnamevalues)");
List nameInvolvements = this.namedparameterJdbcTemplate.query(recordQueryString.toString(), namedParameters, new MyMapper());
You can also use MapSqlParameterSource
String query = "SELECT FIRSTNAME FROM ACTORS WHERE LASTNAME in (:LASTNAME)";
Set<String> ids = ....;
MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("LASTNAME", ids);
this.namedparameterJdbcTemplate.query(query, parameters);