0

I am getting BatchUpdateException while inserting data into PostgreSQl through file

The exception I get is:

Batch entry 0 {call PACKAGE_NAME.PROCEDURE_NAME()} was aborted. Call getNextException to see the cause

Source code is below :-

successMsg = getJdbcTemplate().batchUpdate("{call "+ packageName +"."+ procedureName +sb.toString(),new BatchPreparedStatementSetter(){                 

        @Override
        public void setValues(PreparedStatement ps, int i) throws SQLException 
        {
            String values = insertList.get(i);
            String []valuesArray=values.split(",");
            int parameterCount=ApplicationConstant.ONE;
            for(int valueIndex=0;valueIndex<valuesArray.length;valueIndex++)
            {
                ps.setString(parameterCount++, String.valueOf(valuesArray[valueIndex])!=null?String.valueOf(valuesArray[valueIndex]).trim().replaceAll("@@@", ","):""); //added trim() in order to avoid blank space entry in DB.
            }
            if(financialMonth!=null&&!financialMonth.equals(""))
            {
                ps.setString(parameterCount++,"01-"+financialMonth);
            }
            ps.setInt(parameterCount++,loginBean.getUserId());
            ps.setDate(parameterCount, null);                       
        }   

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

    }); 
  • 1
    What did you get when you followed the advice "Call getNextException to see the cause"? –  Aug 02 '17 at 07:34

1 Answers1

0

As the exception said, you should call getNextException to see the cause.

try{
    successMsg = getJdbcTemplate().batchUpdate("{call "+ packageName +"."+ procedureName +sb.toString(),new BatchPreparedStatementSetter(){                 
} catch (SQLException se) {
    se.getNextException().printStackTrace();
}
Kohei TAMURA
  • 4,970
  • 7
  • 25
  • 49