I'm using Spring-JDBC to execute the SQL and fetch the results.
SELECT
SUM(spend) total_sum
FROM TABLE_NAME
WHERE
sup_id = ? AND
( ( YEAR = ? AND period IN ( ? ) ) OR
( YEAR = ? AND period IN(?)))
And the bind variables are passed as:
final Object[] paramMap = { "1234", "2010",
"'01_JAN','02_FEB','03_MAR'", "2009", "'11_NOV','12_DEC'" };
final List<LeadTimeDto> query = getJdbcTemplate().query(sql, paramMap,
new RowMapper<LeadTimeDto>() {
@Override
public LeadTimeDto mapRow(final ResultSet resultSet,
final int arg1) throws SQLException {
final LeadTimeDto leadTimeDto = new LeadTimeDto();
final String string = resultSet.getString("total_sum");
System.out.println("ltime = " + string);
leadTimeDto.setLeadTime(string);
return leadTimeDto;
}
});
I'm not sure what is happening here. I've the problem with the binding of the THIRD parameter. If I write the value of the third parameter in the query itself as below it is working.
SELECT
SUM(spend) total_sum
FROM TABLE_NAME
WHERE
sup_id = ? AND
( ( YEAR = ? AND period IN ( '01_JAN','02_FEB','03_MAR' ) ) OR
( YEAR = ? AND period IN(?)))
If it is the problem with quotes(') then FIFTH param should have also been the issue. But it is binding fine.
I've tried using getNamedParameterJdbcTemplate() as well both with Map and Bean, but no luck.