【发布时间】:2016-12-15 08:42:57
【问题描述】:
我正在使用弹簧 jdbc 。我的 sql 查询涉及“IN”子句,我动态创建“?”基于输入并通过 spring jdbc模板查询方法的对象数组。
public List<Student> getStudentName(String studentId){
//studentId contains number of ids sepeated by comma.
Object [] params= new Object[]{studentId.split(",")}
Stream<String> stream= Arrays.stream(studentId.split(","));
final String stInClauseParameters= stream.map(studentId -> "?").collect((Collectors.joining(",")));
StringBuilder sql = new StringBuilder();
sql.append(" select studentName from Student where student_id IN ("+stInClauseParameters+")")
return JdbcTemplate.query(sql.toString(),params, new BeanPropertyRowMapper(Student.class))
}
错误
Prepared Statement: Input parameter not set, index: 1.; nested exception is java.sql.SQLException: JZ0SA: Prepared Statement: Input parameter not set, index: 1
spring jdbc查询方法中如何使用数组?
【问题讨论】:
标签: java spring jdbc spring-jdbc