Package java.sql

Examples of java.sql.BatchUpdateException


    } 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;
  }
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

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

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

        s.addBatch("create table t(x int unique not null)");
        for (int i = 0; i < 3; i++) {
            s.addBatch("insert into t values 1");
        }

        BatchUpdateException bue = null;
        try {
            s.executeBatch();
        } catch (BatchUpdateException e) {
            bue = e;
        }
        assertNotNull("Did not get duplicate key exception", bue);

        StringWriter w = new StringWriter();
        bue.printStackTrace(new PrintWriter(w, true));

        String stackTrace = w.toString();
        if (stackTrace.indexOf("duplicate key") == -1) {
            fail("Could not see 'duplicate key' in printStackTrace()", bue);
        }
View Full Code Here

        s.addBatch("create table t(x int unique not null)");
        for (int i = 0; i < 3; i++) {
            s.addBatch("insert into t values 1");
        }

        BatchUpdateException bue = null;
        try {
            s.executeBatch();
        } catch (BatchUpdateException e) {
            bue = e;
        }
        assertNotNull("Did not get duplicate key exception", bue);

        StringWriter w = new StringWriter();
        bue.printStackTrace(new PrintWriter(w, true));

        String stackTrace = w.toString();
        if (stackTrace.indexOf("duplicate key") == -1) {
            fail("Could not see 'duplicate key' in printStackTrace()", bue);
        }
View Full Code Here

                        this.sql = (String) batch[i];
                        db.prepare(this);
                        changes[i] = db.executeUpdate(this, null);
                    }
                    catch (SQLException e) {
                        throw new BatchUpdateException("batch entry " + i + ": " + e.getMessage(), changes);
                    }
                    finally {
                        db.finalize(this);
                    }
                }
View Full Code Here

                rc = step(stmt);
                if (rc != SQLITE_DONE) {
                    reset(stmt);
                    if (rc == SQLITE_ROW) {
                        throw new BatchUpdateException("batch entry " + i + ": query returns results", changes);
                    }
                    throwex();
                }

                changes[i] = changes();
View Full Code Here

        } catch (final IOException e) {
          logger.warn("", e);
        }
      }
    } catch (final BatchUpdateException e) {
      final BatchUpdateException be = e;
      final int[] updateCounts = be.getUpdateCounts();
      if (updateCounts != null) {
        for (int i = 0; i < updateCounts.length; i++) {
          final int j = updateCounts[i];
          if (j < 0) {
            logger.error("SQL errorcode: " + j + " -> in SQL\n" + allSql.get(Integer.valueOf(i)));
View Full Code Here

  static public boolean isSQLException(HibernateException e, String message) {
    boolean isSQLException = false;

    if (e.getCause() instanceof BatchUpdateException) {
      BatchUpdateException be = (BatchUpdateException) e.getCause();
      if (be.getNextException() instanceof SQLException) {
        SQLException sqle = (SQLException) be.getNextException();
        isSQLException = sqle.getMessage().equals(message);
      }
    }
    return isSQLException;
  }
View Full Code Here

    } catch (HibernateException e) {
      Hiber.rollBack();
      if (HttpException
          .isSQLException(e,
              "ERROR: duplicate key violates unique constraint \"mpan_dno_id_key\"")) {
        BatchUpdateException be = (BatchUpdateException) e.getCause();
        String message = be.getMessage();
        boolean isImport = message.charAt(message.lastIndexOf(',') - 1) == '0';
        throw new UserException("An MPAN with this "
            + (isImport ? "import" : "export")
            + " MPAN core already exists.");
      } else {
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.