当前位置: 首页>>代码示例>>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;未经允许,请勿转载。