0
我正在使用批量插入從我的Java應用程序到MySQL數據庫的批量數據加載。對於編譯失敗執行的結果,我們正在處理以下列方式的BatchUpdateException:mysql jdbc連接器批量更新異常更新計數不如預期
catch (BatchUpdateException e)
{
int[] codes = e.getUpdateCounts();
for (int i = 0; i<codes.length; i++)
{
if (Statement.EXECUTE_FAILED == codes[i])
{
lr.recordLoadCount--;
//`records` is a List containing the objects which were
//added in this batch
lr.addFailReason(records.get(i).xmlString());
}
}
lr.addException(e.getMessage());
}
我跑,所有的執行會失敗的情況下(表不存在)。所以理想情況下,我會爲每條記錄添加失敗原因。
但是,我可以發現除第一個記錄以外的所有內容都被添加了。當我調試代碼時,我發現代碼[0]以'-1'出現,而所有其他代碼以'-3'出現(即Statement.EXECUTE_FAILED)。
按的Javadoc:
public int[] getUpdateCounts() Returns: an array of int containing the update counts for the updates that were executed successfully before this error occurred. Or, if the driver continues to process commands after an error, one of the following for every command in the batch: - an update count - Statement.SUCCESS_NO_INFO ('-2') - Statement.EXECUTE_FAILED ('-3')
問: 難道MySQL連接/ J設置不正確的更新計數批處理中第一個執行失敗,或者我在這裏失去了一些東西?有沒有人遇到過這種情況?
我使用connector/J 5.1.30; Ubuntu上的Mysql 5.5.24 12.04
聽起來像一個錯誤,也許你應該在Oracle上提交一張票。 –
@MarkRotteveel似乎如此。只是想在我提出票之前確認。謝謝。 –