0
我正在使用spring jdbc。我的SQL查詢涉及'IN'子句,我動態地創建'?'根據輸入並將 對象數組傳遞給spring jdbc模板的查詢方法。如何在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
如何使用在簧JDBC查詢法陣?