Package java.sql

Examples of java.sql.BatchUpdateException


        String[] theFinalStates4 = init1; // Message state

        Exception[] theExceptions = { null, null, null, null, null, null, null,
                null, null, null, null };

        BatchUpdateException aBatchUpdateException;
        int loopCount = init1.length;
        for (int i = 0; i < loopCount; i++) {
            try {
                aBatchUpdateException = new BatchUpdateException(init1[i],
                        init2[i], init3[i]);
                if (theExceptions[i] != null) {
                    fail();
                }
                assertEquals(i + " Final state mismatch: ",
                        aBatchUpdateException.getErrorCode(),
                        theFinalStates1[i]);
                assertEquals(i + " Final state mismatch: ",
                        aBatchUpdateException.getUpdateCounts(),
                        theFinalStates2[i]);
                assertEquals(i + " Final state mismatch: ",
                        aBatchUpdateException.getSQLState(), theFinalStates3[i]);
                assertEquals(i + " Final state mismatch: ",
                        aBatchUpdateException.getMessage(), theFinalStates4[i]);

            } catch (Exception e) {
                if (theExceptions[i] == null) {
                    fail(i + "Unexpected exception");
                }
View Full Code Here


        String[] theFinalStates4 = init1; // Message state

        Exception[] theExceptions = { null, null, null, null, null, null, null,
                null, null, null, null };

        BatchUpdateException aBatchUpdateException;
        int loopCount = init1.length;
        for (int i = 0; i < loopCount; i++) {
            try {
                aBatchUpdateException = new BatchUpdateException(init1[i],
                        init2[i], init3[i], init4[i]);
                if (theExceptions[i] != null) {
                    fail();
                }
                assertEquals(i + " Final state mismatch: ",
                        aBatchUpdateException.getErrorCode(),
                        theFinalStates1[i]);
                assertEquals(i + " Final state mismatch: ",
                        aBatchUpdateException.getUpdateCounts(),
                        theFinalStates2[i]);
                assertEquals(i + " Final state mismatch: ",
                        aBatchUpdateException.getSQLState(), theFinalStates3[i]);
                assertEquals(i + " Final state mismatch: ",
                        aBatchUpdateException.getMessage(), theFinalStates4[i]);

            } catch (Exception e) {
                if (theExceptions[i] == null) {
                    fail(i + "Unexpected exception");
                }
View Full Code Here

  public void testBatchExceptionTranslation() {
    SQLExceptionTranslator sext = new SQLErrorCodeSQLExceptionTranslator(ERROR_CODES);

    SQLException badSqlEx = new SQLException("", "", 1);
    BatchUpdateException batchUpdateEx = new BatchUpdateException();
    batchUpdateEx.setNextException(badSqlEx);
    BadSqlGrammarException bsgex = (BadSqlGrammarException) sext.translate("task", "SQL", batchUpdateEx);
    assertEquals("SQL", bsgex.getSql());
    assertEquals(badSqlEx, bsgex.getSQLException());
  }
View Full Code Here

  @Test
  public void testBatchUpdateWithBatchFailure() throws Exception {
    final String[] sql = {"A", "B", "C", "D"};
    given(this.statement.executeBatch()).willThrow(
        new BatchUpdateException(new int[] { 1, Statement.EXECUTE_FAILED, 1,
          Statement.EXECUTE_FAILED }));
    mockDatabaseMetaData(true);
    given(this.connection.createStatement()).willReturn(this.statement);

    JdbcTemplate template = new JdbcTemplate(this.dataSource, false);
View Full Code Here

    } catch (final Throwable t) {
      boolean isBatchUpdateException = false;
      // We need to capture nested exception of BatchUpdate exception.
      Throwable cause = t.getCause();
      if (cause instanceof BatchUpdateException) {
        BatchUpdateException batchUpdateException = (BatchUpdateException) cause;
        if (batchUpdateException.getNextException() != null) {
          String errorMessage = batchUpdateException.getNextException().getMessage();
          String messageKey = errorMessage.substring("ERROR:".length()).trim();
          isBatchUpdateException = true;
          ir.setErrorMessages("isBatchUpdateException:" + messageKey);
        }
      }
View Full Code Here

    addBatchItems(statement, pStmt, tableName, ++c);
    addBatchItems(statement, pStmt, tableName, ++c);

    int expectedUpdateCounts = continueBatchOnError ? 6 : 3;

    BatchUpdateException e1 = null;
    BatchUpdateException e2 = null;

    int[] updateCountsPstmt = null;
    try {
      updateCountsPstmt = pStmt.executeBatch();
    } catch (BatchUpdateException e) {
View Full Code Here

                        error = true;
                    }
                }
                batchCommands = null;
                if (error) {
                    throw new BatchUpdateException(result);
                }
                return result;
            } finally {
                afterWriting();
            }
View Full Code Here

            updateCounts[i] = ((Integer) data[0]).intValue();
        }

        if (updateCounts.length != batchCount) {
            if (errorResult == null) {
                throw new BatchUpdateException(updateCounts);
            } else {
                errorResult.getMainString();

                throw new BatchUpdateException(errorResult.getMainString(),
                        errorResult.getSubString(),
                        errorResult.getErrorCode(), updateCounts);
            }
        }
View Full Code Here

            updateCounts[i] = ((Integer) data[0]).intValue();
        }

        if (updateCounts.length != batchCount) {
            if (errorResult == null) {
                throw new BatchUpdateException(updateCounts);
            } else {
                errorResult.getMainString();

                throw new BatchUpdateException(errorResult.getMainString(),
                        errorResult.getSubString(),
                        errorResult.getErrorCode(), updateCounts);
            }
        }
View Full Code Here

                runningUpdateCount += this.lastUpdateCount;
            }
            catch(SQLException x)
            {
                updateCounts[i] = EXECUTE_FAILED;
                throw new BatchUpdateException(Arrays.copyOf(updateCounts, i+1), x);
            }
        }

        // replace the update count from the last statement with the update count
        // from the last batch.
View Full Code Here

TOP

Related Classes of java.sql.BatchUpdateException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.