当前位置: 首页>>代码示例>>Java>>正文


Java BatchUpdateException类代码示例

本文整理汇总了Java中java.sql.BatchUpdateException的典型用法代码示例。如果您正苦于以下问题:Java BatchUpdateException类的具体用法?Java BatchUpdateException怎么用?Java BatchUpdateException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BatchUpdateException类属于java.sql包,在下文中一共展示了BatchUpdateException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleExceptionForBatch

import java.sql.BatchUpdateException; //导入依赖的package包/类
protected SQLException handleExceptionForBatch(int endOfBatchIndex, int numValuesPerBatch, long[] updateCounts, SQLException ex)
        throws BatchUpdateException, SQLException {
    for (int j = endOfBatchIndex; j > endOfBatchIndex - numValuesPerBatch; j--) {
        updateCounts[j] = EXECUTE_FAILED;
    }

    if (this.continueBatchOnError && !(ex instanceof MySQLTimeoutException) && !(ex instanceof MySQLStatementCancelledException)
            && !hasDeadlockOrTimeoutRolledBackTx(ex)) {
        return ex;
    } // else: throw the exception immediately

    long[] newUpdateCounts = new long[endOfBatchIndex];
    System.arraycopy(updateCounts, 0, newUpdateCounts, 0, endOfBatchIndex);

    throw SQLError.createBatchUpdateException(ex, newUpdateCounts, getExceptionInterceptor());
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:17,代码来源:StatementImpl.java

示例2: test13

import java.sql.BatchUpdateException; //导入依赖的package包/类
/**
 * De-Serialize a BatchUpdateException from JDBC 4.0 and make sure you can
 * read it back properly
 */
@Test
public void test13() throws Exception {
    String reason1 = "This was the error msg";
    String state1 = "user defined sqlState";
    String cause1 = "java.lang.Throwable: throw 1";
    int errorCode1 = 99999;
    Throwable t = new Throwable("throw 1");
    int[] uc1 = {1, 2, 21};
    long[] luc1 = {1, 2, 21};

    ObjectInputStream ois = new ObjectInputStream(
            new ByteArrayInputStream(SerializedBatchUpdateException.DATA));
    BatchUpdateException bue = (BatchUpdateException) ois.readObject();
    assertTrue(reason1.equals(bue.getMessage())
            && bue.getSQLState().equals(state1)
            && bue.getErrorCode() == errorCode1
            && cause1.equals(bue.getCause().toString())
            && Arrays.equals(bue.getLargeUpdateCounts(), luc1)
            && Arrays.equals(bue.getUpdateCounts(), uc1));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:25,代码来源:BatchUpdateExceptionTests.java

示例3: test14

import java.sql.BatchUpdateException; //导入依赖的package包/类
/**
 * Serialize a BatchUpdateException with an Integer.MAX_VALUE + 1 and
 * validate you can read it back properly
 */
@Test
public void test14() throws Exception {
    int[] uc1 = {Integer.MAX_VALUE, Integer.MAX_VALUE + 1};
    long[] luc1 = {Integer.MAX_VALUE, Integer.MAX_VALUE + 1};
    BatchUpdateException be = new BatchUpdateException(reason, state, errorCode,
            luc1, t);
            BatchUpdateException bue
            = createSerializedException(be);
    assertTrue(reason.equals(bue.getMessage())
            && bue.getSQLState().equals(state)
            && cause.equals(bue.getCause().toString())
            && bue.getErrorCode() == errorCode
            && Arrays.equals(bue.getLargeUpdateCounts(), luc1)
            && Arrays.equals(bue.getUpdateCounts(), uc1));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:BatchUpdateExceptionTests.java

示例4: test16

import java.sql.BatchUpdateException; //导入依赖的package包/类
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test16() {
    BatchUpdateException ex = new BatchUpdateException("Exception 1", uc,  t1);
    BatchUpdateException ex1 = new BatchUpdateException("Exception 2", uc);
    BatchUpdateException ex2 = new BatchUpdateException("Exception 3", uc, t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    SQLException sqe = ex;
    int num = 0;
    while (sqe != null) {
        assertTrue(msgs[num++].equals(sqe.getMessage()));
        Throwable c = sqe.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        sqe = sqe.getNextException();
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:24,代码来源:BatchUpdateExceptionTests.java

示例5: testException

import java.sql.BatchUpdateException; //导入依赖的package包/类
private void testException() throws SQLException {
    deleteDb("batchUpdates");
    conn = getConnection("batchUpdates");
    stat = conn.createStatement();
    stat.execute("create table test(id int primary key)");
    prep = conn.prepareStatement("insert into test values(?)");
    for (int i = 0; i < 700; i++) {
        prep.setString(1, "x");
        prep.addBatch();
    }
    try {
        prep.executeBatch();
    } catch (BatchUpdateException e) {
        PrintStream temp = System.err;
        try {
            ByteArrayOutputStream buff = new ByteArrayOutputStream();
            PrintStream p = new PrintStream(buff);
            System.setErr(p);
            e.printStackTrace();
        } finally {
            System.setErr(temp);
        }
    }
    conn.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:26,代码来源:TestBatchUpdates.java

示例6: testExecuteBatch03

import java.sql.BatchUpdateException; //导入依赖的package包/类
private void testExecuteBatch03() throws SQLException {
    trace("testExecuteBatch03");
    boolean batchExceptionFlag = false;
    String sPrepStmt = COFFEE_SELECT;
    trace("Prepared Statement String :" + sPrepStmt);
    prep = conn.prepareStatement(sPrepStmt);
    prep.setInt(1, 1);
    prep.addBatch();
    try {
        int[] updateCount = prep.executeBatch();
        trace("Update Count" + updateCount.length);
    } catch (BatchUpdateException b) {
        batchExceptionFlag = true;
    }
    if (batchExceptionFlag) {
        trace("select not allowed; correct");
    } else {
        fail("executeBatch select");
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:21,代码来源:TestBatchUpdates.java

示例7: testExecuteBatch06

import java.sql.BatchUpdateException; //导入依赖的package包/类
private void testExecuteBatch06() throws SQLException {
    trace("testExecuteBatch06");
    boolean batchExceptionFlag = false;
    // Insert a row which is already Present
    String sInsCoffee = COFFEE_INSERT1;
    String sDelCoffee = COFFEE_DELETE1;
    stat.addBatch(sInsCoffee);
    stat.addBatch(sInsCoffee);
    stat.addBatch(sDelCoffee);
    try {
        stat.executeBatch();
    } catch (BatchUpdateException b) {
        batchExceptionFlag = true;
        for (int uc : b.getUpdateCounts()) {
            trace("Update counts:" + uc);
        }
    }
    if (batchExceptionFlag) {
        trace("executeBatch insert duplicate; correct");
    } else {
        fail("executeBatch");
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:24,代码来源:TestBatchUpdates.java

示例8: testExecuteBatch07

import java.sql.BatchUpdateException; //导入依赖的package包/类
private void testExecuteBatch07() throws SQLException {
    trace("testExecuteBatch07");
    boolean batchExceptionFlag = false;
    String selectCoffee = COFFEE_SELECT1;
    trace("selectCoffee = " + selectCoffee);
    Statement stmt = conn.createStatement();
    stmt.addBatch(selectCoffee);
    try {
        int[] updateCount = stmt.executeBatch();
        trace("updateCount Length : " + updateCount.length);
    } catch (BatchUpdateException be) {
        batchExceptionFlag = true;
    }
    if (batchExceptionFlag) {
        trace("executeBatch select");
    } else {
        fail("executeBatch");
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:20,代码来源:TestBatchUpdates.java

示例9: printIfBad

import java.sql.BatchUpdateException; //导入依赖的package包/类
private void printIfBad(int seed, int id, int objectId, Throwable t) {
    if (t instanceof BatchUpdateException) {
        // do nothing
    } else if (t.getClass().getName().contains("SQLClientInfoException")) {
        // do nothing
    } else if (t instanceof SQLException) {
        SQLException s = (SQLException) t;
        int errorCode = s.getErrorCode();
        if (errorCode == 0) {
            printError(seed, id, s);
        } else if (errorCode == ErrorCode.OBJECT_CLOSED) {
            if (objectId >= 0 && objects.size() > 0) {
                // TODO at least call a few more times after close - maybe
                // there is still an error
                objects.remove(objectId);
            }
        } else if (errorCode == ErrorCode.GENERAL_ERROR_1) {
            // General error [HY000]
            printError(seed, id, s);
        }
    } else {
        printError(seed, id, t);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:25,代码来源:TestCrashAPI.java

示例10: testBatchUpdateWithBatchFailure

import java.sql.BatchUpdateException; //导入依赖的package包/类
@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);
	try {
		template.batchUpdate(sql);
	}
	catch (UncategorizedSQLException ex) {
		assertThat(ex.getSql(), equalTo("B; D"));
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:JdbcTemplateTests.java

示例11: assertBatchExecuteError

import java.sql.BatchUpdateException; //导入依赖的package包/类
/**
 * helper method to evaluate negative tests where we expect a
 * batchExecuteException to be returned.
 * @exception SQLException     Thrown if the expected error occurs
 *                             We expect a BatchUpdateException, and
 *                             verify it is so.
 *
 * @param expectedError The sqlstate to look for.
 * @param stmt The Statement that contains the Batch to
 *                             be executed.
 * @param expectedUpdateCount The expectedUpdateCount array.
 */
protected void assertBatchExecuteError(
    String expectedError,
    Statement stmt,
    int[] expectedUpdateCount)
throws SQLException
{
    int[] updateCount;
    try {
        updateCount = stmt.executeBatch();
        fail("Expected batchExecute to fail");
    } catch (BatchUpdateException bue) {
        assertSQLState(expectedError, bue);
        updateCount = bue.getUpdateCounts();
        assertBatchUpdateCounts(expectedUpdateCount, updateCount);
    }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:29,代码来源:BatchUpdateTest.java

示例12: createErrorXML

import java.sql.BatchUpdateException; //导入依赖的package包/类
/**
 * Creates an error xml result String using the information from the passed in Throwable.
 * 
 * @param t
 *          the Throwable used to set the error message
 * @return the xml error String, e.g. <error><message>An error occurred</message></error>
 */
public String createErrorXML(Throwable t) {
  Throwable x = t;
  final StringBuilder sb = new StringBuilder(t.getMessage());

  // prevent infinite cycling
  while (x.getCause() != null
      || (x instanceof BatchUpdateException && ((BatchUpdateException) x).getNextException() != null)) {
    final Throwable prevX = x;
    if (x instanceof BatchUpdateException) {
      x = ((BatchUpdateException) x).getNextException();
    } else {
      x = x.getCause();
    }
    if (x == prevX) {
      break;
    }
    sb.append("\nCaused by: " + x.getMessage());
  }

  return "<ob:error xmlns:ob=\"" + XMLConstants.OPENBRAVO_NAMESPACE + "\"><message>" + sb
      + "</message></ob:error>";
}
 
开发者ID:mauyr,项目名称:openbravo-brazil,代码行数:30,代码来源:WebServiceUtil.java

示例13: handleExceptionForBatch

import java.sql.BatchUpdateException; //导入依赖的package包/类
protected SQLException handleExceptionForBatch(int endOfBatchIndex, int numValuesPerBatch, int[] updateCounts, SQLException ex) throws BatchUpdateException {
    SQLException sqlEx;

    for (int j = endOfBatchIndex; j > endOfBatchIndex - numValuesPerBatch; j--) {
        updateCounts[j] = EXECUTE_FAILED;
    }

    if (this.continueBatchOnError && !(ex instanceof MySQLTimeoutException) && !(ex instanceof MySQLStatementCancelledException)
            && !hasDeadlockOrTimeoutRolledBackTx(ex)) {
        sqlEx = ex;
    } else {
        int[] newUpdateCounts = new int[endOfBatchIndex];
        System.arraycopy(updateCounts, 0, newUpdateCounts, 0, endOfBatchIndex);

        BatchUpdateException batchException = new BatchUpdateException(ex.getMessage(), ex.getSQLState(), ex.getErrorCode(), newUpdateCounts);
        batchException.initCause(ex);
        throw batchException;
    }

    return sqlEx;
}
 
开发者ID:mniepert,项目名称:TPKB,代码行数:22,代码来源:StatementImpl.java

示例14: processBatch

import java.sql.BatchUpdateException; //导入依赖的package包/类
protected void processBatch()
{
  logger.debug("start {} end {}", batchStartIdx, tuples.size());
  try {
    for (int i = batchStartIdx; i < tuples.size(); i++) {
      setStatementParameters(updateCommand, tuples.get(i));
      updateCommand.addBatch();
    }
    updateCommand.executeBatch();
    updateCommand.clearBatch();
    batchStartIdx += tuples.size() - batchStartIdx;
  } catch (BatchUpdateException bue) {
    logger.error(bue.getMessage());
    processUpdateCounts(bue.getUpdateCounts(), tuples.size() - batchStartIdx);
  } catch (SQLException e) {
    throw new RuntimeException("processing batch", e);
  }
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:19,代码来源:AbstractJdbcTransactionableOutputOperator.java

示例15: processBatch

import java.sql.BatchUpdateException; //导入依赖的package包/类
@Override
protected void processBatch()
{
  logger.debug("start {} end {}", batchStartIdx, tuples.size());
  try {
    for (int i = batchStartIdx; i < tuples.size(); i++) {
      String copyStmt = generateCopyStatement(tuples.get(i));
      stmt.addBatch(copyStmt);
    }
    stmt.executeBatch();
    stmt.clearBatch();
    batchStartIdx += tuples.size() - batchStartIdx;
  } catch (BatchUpdateException bue) {
    logger.error(bue.getMessage());
    processUpdateCounts(bue.getUpdateCounts(), tuples.size() - batchStartIdx);
  } catch (SQLException e) {
    throw new RuntimeException("processing batch", e);
  }
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:20,代码来源:RedshiftJdbcTransactionableOutputOperator.java


注:本文中的java.sql.BatchUpdateException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。