public int[] executeBatch() throws BatchUpdateException { if (batches == null) return new int[0]; final int[] result = new int[batches.size()]; BatchUpdateException failed = null; for (int i = 0; i < result.length; i++) { try { result[i] = executeUpdate((String) batches.get(i)); } catch (SQLException ex) { result[i] = EXECUTE_FAILED; if (failed == null) { failed = new BatchUpdateException( ex.getMessage(), ex.getSQLState(), ex.getErrorCode(), result); failed.initCause(ex); } failed.setNextException(ex); } } batches.clear(); if (failed != null) throw failed; return result; }