The error message 'Parameter index out of range' suggests that there are no parameters present in the query, even though a parameter :values is used. This is because jdbcTemplate.queryForList() doesn't recognize named parameters like :values.

To fix this, use the NamedParameterJdbcTemplate class, which supports named parameters in queries. Here's how to modify the code:

String selectDsDept = 'select id, un_code from t_dept where un_code in (:values)';
Map<String, Object> paramMap = Collections.singletonMap('values', dsUnicodeList);
List<Map<String, Object>> dsMapList = namedParameterJdbcTemplate.queryForList(selectDsDept, paramMap);

Make sure to initialize namedParameterJdbcTemplate with the correct DataSource before using it.

解决 Java 中使用 jdbcTemplate 时出现的 'Parameter index out of range' 错误

原文地址: https://www.cveoy.top/t/topic/qAj6 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录