即使批量更新中有 1 个插入失败,仍继续插入 Spring JdbcTemplate

use*_*829 5 java error-handling spring spring-jdbc jdbctemplate

下面的方法将插入学生记录列表。

公共无效insertListOfPojos(最终列表myPojoList){

    String sql = "INSERT INTO " + "Student " + "(name,age) " + "VALUES "
            + "(?,?)";

    jdbcTemplateObject.batchUpdate(sql, new BatchPreparedStatementSetter() {

        @Override
        public void setValues(PreparedStatement ps, int i)
                throws SQLException {

            Student myPojo = myPojoList.get(i);
            ps.setString(1, myPojo.getName());
            ps.setInt(2, myPojo.getAge());

        }

        @Override
        public int getBatchSize() {
            return myPojoList.size();
        }
    });

}
Run Code Online (Sandbox Code Playgroud)

问题:- 假设 5 条记录中的列值太大,则执行停止。即使第五条记录的插入失败,我也希望继续执行。