-1
executeBatch()將拋出兩個異常SQLException和BatchUpdateException。需要關於如何處理這個異常的幫助。executeBatch異常處理
我們對分佈式環境執行900批量限制和150個提交限制。僅處理唯一的BatchUpdateException。以下是代碼片段。有人可以指導我們是否需要捕獲SQLException。如果沒有捕獲到SQLException,結果如何。
拋出: SQLException - 如果發生數據庫訪問錯誤,在已關閉的Statement上調用此方法,或者驅動程序不支持批處理語句。 ---這個說法是什麼意思。
} catch (BatchUpdateException be) {
status = "failure";
errorDesc = "BatchUpdateException";
errorCode = "-1";
checkpoint = "12";
log.debug(DealerId + "->BatchException be:" + be + ", checkpoint: " + checkpoint
+ ",con: " + con + ",db2con: " + db2Con);
int[] updateStatus = be.getUpdateCounts();
if (updateStatus != null) {
ArrayList<String> failedList = new ArrayList<String>();
try {
verifyUpdateCount(updateStatus, failedList, batchQueryList, queryList);
} catch (Exception e) {
if (failedList.size() > 0) {
log.debug(DealerId + "->updateStatus Exception queryList size:"
+ queryList.size());
queryList.clear();
queryList.addAll(failedList);
}
log.debug(DealerId + "->updateStatus Exception e:" + e + ", checkpoint: "
+ checkpoint + "con: " + con + "db2con: " + db2Con);
}
}
break END;
} finally {
try {
log.debug("norecords:" + noRecords);
if (!noRecords) {
closeStatements(ps, rs, rsShdw, db2Ps, stShdw);
}
} catch (Exception e) {
printCheckpoint(queryList, con, db2Con, "closeStatements Exception e: ", e,
checkpoint);
}
}
如果我們還捕獲了SQLException,則會捕獲BatchUpdateException。這是否需要? – user2077937
'BatchUpdateException擴展了SQLException',所以如果你捕捉到後者,你不需要去捕捉前者,除非你想以不同的方式處理它 –