本文整理汇总了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();
}
示例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);
}
}
示例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);
}
}
示例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());
}
}