It looks like you are mixing the name and position parameters. It is best to use one or the other, but not both.
Try
MapSqlParameterSource parameters = new MapSqlParameterSource(); parameters.addValue("ids", year); parameters.addValue("provnum", provnum); return this.template.getJdbcOperations().query( "SELECT * FROM INCOME WHERE PROVNUM=:provnum AND FISCALDATE IN ( :ids )", this.rowMapper, parameters);
After your comment, I see that you are using the wrong overload of the query() method: there are quite a lot to choose from, so itβs not surprising that some errors can be painted over!
You need to call
return this.template.getJdbcOperations().query( "SELECT ... etc.", parameters, this.rowMapper);
In the original call, you call the version of query(String sql, RowMapper mapper, Object... params) that expects alphabetic parameters. The revised call is the query (String sql, SqlParameterSource params, RowMapper mapper) - the SqlParamtersSource key as the second argument. Also, it's just worth checking that you are using NamedParameterJdbcTemplate .
source share