本文整理匯總了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());
}
}