當前位置: 首頁>>代碼示例>>Java>>正文


Java BatchUpdateException.printStackTrace方法代碼示例

本文整理匯總了Java中java.sql.BatchUpdateException.printStackTrace方法的典型用法代碼示例。如果您正苦於以下問題:Java BatchUpdateException.printStackTrace方法的具體用法?Java BatchUpdateException.printStackTrace怎麽用?Java BatchUpdateException.printStackTrace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.sql.BatchUpdateException的用法示例。


在下文中一共展示了BatchUpdateException.printStackTrace方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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

示例2: testUnderlyingExceptionIsVisible

import java.sql.BatchUpdateException; //導入方法依賴的package包/類
/**
 * Test that the underlying exception is included in the output when we
 * call printStackTrace() on a BatchUpdateException. Earlier, with the
 * client driver, the underlying cause of a BatchUpdateException could not
 * be seen without calling getNextException().
 */
public void testUnderlyingExceptionIsVisible() throws SQLException {
    setAutoCommit(false);
    Statement s = createStatement();
    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);
    }
}
 
開發者ID:splicemachine,項目名稱:spliceengine,代碼行數:31,代碼來源:BatchUpdateTest.java

示例3: testUnderlyingExceptionIsVisible

import java.sql.BatchUpdateException; //導入方法依賴的package包/類
/**
     * Test that the underlying exception is included in the output when we
     * call printStackTrace() on a BatchUpdateException. Earlier, with the
     * client driver, the underlying cause of a BatchUpdateException could not
     * be seen without calling getNextException().
     */
    public void testUnderlyingExceptionIsVisible() throws SQLException {
// GemStone changes BEGIN
        Connection conn = getConnection();
        conn.setAutoCommit(false);
        Statement s = conn.createStatement();
        /* (original code)
        setAutoCommit(false);
        Statement s = createStatement();
        */
// GemStone changes END
        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);
        }
    }
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:38,代碼來源:BatchUpdateTest.java

示例4: insertJsonResponse

import java.sql.BatchUpdateException; //導入方法依賴的package包/類
public static void insertJsonResponse(int curConsId, TreeMap<Integer, String> input) throws SQLException {
        try {
            String insertSQL = "INSERT INTO enhancedentities "
                    + "(consultation_id,article_id,json_text) VALUES"
                    + "(?,?,?);";
            PreparedStatement prepStatement = connection.prepareStatement(insertSQL);
//            connection.setAutoCommit(false);
            for (int curArticle : input.keySet()) {
                String json_text = input.get(curArticle);
                prepStatement.setInt(1, curConsId);
                prepStatement.setInt(2, curArticle);
                prepStatement.setString(3, json_text);
//                prepStatement.executeUpdate();
                prepStatement.addBatch();
            }
            prepStatement.executeBatch();
//            connection.commit();
            prepStatement.close();

//            for (int i = 0; i<x.length; i++){
//                System.out.println(x[i]);
//            }
        } catch (BatchUpdateException ex) {
            ex.printStackTrace();
//            System.out.println(ex.getNextException());
        }
    }
 
開發者ID:scify,項目名稱:Democracit-annotators-entityExtractor,代碼行數:28,代碼來源:DB.java


注:本文中的java.sql.BatchUpdateException.printStackTrace方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。