2014-02-15 28 views
-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); 
    } 
} 

回答

0

拋出:SQLException - 如果發生數據庫訪問錯誤,這種方法被稱爲在一個封閉的語句或驅動程序不支持批量語句。 ---這個說法是什麼意思。

我不知道它是否可以變得比這更簡單。你不明白哪一部分?

它說,該方法在下列情況之一拋出SQLException:發生

  • 數據庫訪問錯誤,
  • 這種方法被調用關閉的Statement
  • 驅動程序不支持批量語句。
+0

如果我們還捕獲了SQLException,則會捕獲BatchUpdateException。這是否需要? – user2077937

+0

'BatchUpdateException擴展了SQLException',所以如果你捕捉到後者,你不需要去捕捉前者,除非你想以不同的方式處理它 –