title: How can I retry the statements that were not executed after a batch execution fails?
body: <p>I'm need to update a table with data from a CSV. All data is validated before the update takes place: a validation method (witch is not presented bellow) checks if some assumptions are true and "flags" the object as valid or invalid. I've already test it a lot and it's working exactly as I want.</p>
  
  <p>Even so, I would like to guarantee that all Statements will be executed even if there's a fail on a batch, something that I was not able to think about. If this happens, I want the batch in witch this fail statement is to be skipped and that the next one is executed.</p>
  
  <pre><code>public void updateTable(List&lt;PersonBean&gt; personList) {
  
      Connection connection = null;
      PreparedStatement ps = null;
  
      String updateDBPersonSQL = "UPDATE Person set merge_parent_id = ? WHERE id = ?";
  
      try {
          logger.info("DATA UPDATING STARTED");
  
          input = new FileInputStream("resources/propertiesFiles/applications.properties");
          properties.load(input);
  
          final int batchSize = Integer.parseInt(properties.getProperty("batchSize"));
  
          connection = DBConnection.getConnection();
          connection.setAutoCommit(false);
  
          int validObj = 0;
  
          ps = connection.prepareStatement(updateDBPersonSQL);
  
          for (int i = 0; i &lt; personList.size(); i++) {
  
              PersonBean person = personList.get(i);
  
              if (person.getValidationStatus().equals("valid")) {
  
                  ps.setInt(1, person.getMerge_parent_id());
                  ps.setInt(2, person.getId());
                  ps.addBatch();
  
                  validObj++;
  
                  if (validObj % batchSize == 0 &amp;&amp; validObj != 0) {
                      ps.executeBatch();
                      connection.commit();
  
                      logger.info((batchSize) + " rows updated");
                  } 
              }
          }
          int [] batchCount = ps.executeBatch();
          connection.commit();
  
          logger.info(batchCount.length + " rows updated");
  
          writeValidationStatusToCSV(personList);
  
      } catch (BatchUpdateException e) {
          int [] updateCount = e.getUpdateCounts();
  
              for (int i = 0; i &lt; updateCount.length; i++) {
  
                  if (updateCount[i] &gt;= 0) {
  
                      logger.info(updateCount.length + " objects updated.");
  
                  } else if (updateCount[i] == Statement.EXECUTE_FAILED) {
  
                      ?????
                  }
              }
          logger.error(updateCount.length);
          logger.error("BatchUpdateException: " + e);
          logger.error("getNextException: " + e.getNextException());
  
          try {
              connection.rollback();
          } catch (SQLException e1) {
              logger.error("Rollback error: " + e1, e1);
          }
      } finally {
          if (ps!= null) {
              try {
                  ps.close();
              } catch (SQLException e) {
                  logger.info(e);
              }
          }
      }
      logger.info("DATA UPDATING FINISHED");
  }
  </code></pre>
  
  <p>I saw a lot of material about how to handle the exception, but none explained or pointed me to the direction of how to retry the next Statements, it means, how to execute the next batch.</p>
  
  <p>How do I manage to do this?</p>
  
  <p>EDIT: I'm using Postgresql</p>