5

The below method will insert a List of student recors.

public void insertListOfPojos(final List 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();
        }
    });

}

Problem :- Say if the values of a column in 5 record is too large then the execution stops. I want the execution to continue even if the insertion of 5th record fails.

user1454829
  • 79
  • 1
  • 2
  • 7
  • Duplicate to http://stackoverflow.com/questions/9809503/spring-jdbctemplate-batchupdate-handling-exceptions – Alexander Jardim Jun 27 '13 at 21:36
  • Using a oracle.jdbc.driver.OracleDriver.I get the below exception when insert a record with invalid data---Exception in thread "main" org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [INSERT INTO Student (name,age) VALUES (?,?)]; SQL state [72000]; error code [12899]; ORA-12899: value too large for column "CIBESDBO"."STUDENT"."NAME" (actual: 25, maximum: 20) ; nested exception is java.sql.BatchUpdateException: ORA-12899: value too large for column "CIBESDBO"."STUDENT"."NAME" (actual: 25, maximum: 20) I need to continue insertion. – user1454829 Jul 02 '13 at 21:39

0 Answers0