0

I am getting below exception :

ERROR 1 --- [eduler_Worker-3] jdbc.sqltiming
: 123. PreparedStatement.setObject(1, {ids=[33925]})

com.microsoft.sqlserver.jdbc.SQLServerException: The index 1 is out of range. Caused by: org.springframework.dao.TransientDataAccessResourceException: PreparedStatementCallback; SQL [select * from tableA t1 WHERE t1.id IN (:ids)]; The index 1 is out of range.; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: The index 1 is out of range.

Below is the code:

    @Override
    @SneakyThrows
    public void publish(List<Long> ids) {
        val result = jdbcTemplate.queryForList("select * from tableA t1 WHERE t1.id IN (:ids)",ImmutableMap.of("ids", ids));
}

I am unable to understand that why is it trying to put at index 1 while I am using named parameter in the query. Please help

codeLover
  • 2,571
  • 1
  • 11
  • 27
  • 1
    JdbcTemplate doesn't support named parameters. Make sure you use NamedParameterJdbcTemplate. https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/jdbc/core/namedparam/NamedParameterJdbcTemplate.html#queryForList-java.lang.String-java.util.Map-java.lang.Class- – JB Nizet Apr 01 '19 at 07:00
  • Ahh my bad..thanks for the help – codeLover Apr 01 '19 at 07:13

0 Answers0