在專案中用到了JDBC的批處理Batch,程式偶爾會報錯,e.getMessage()只得到了一個單詞“Error”
有時可以正常執行通過,有時會拋SQLException的例外,感覺很奇怪,例外資訊也很奇怪代碼大致如下:
private void BatchInsertData(List<BeanClass> list, Connection connection) {
try{
PrepareStatement ps = connection.prepareStatement("insert into A(A_ID, A_NAME, A_ENGLISH_NAME, A_ADDERSS, A_PHONE_NUMBER)VALUES(A_SEQUENCE.NEXTVAL, ?, ?, ?, ?)");
list.forEach(beanClass -> {
if(beanClss.getName()==null) {
ps.setNull(1, Types.VARCHAR);
} else {
ps.setString(1, beanClss.getName())
}
if(beanClss.getEnglishName()==null) {
ps.setNull(2, Types.VARCHAR);
} else {
ps.setString(2, beanClss.getEnglishName())
}
...
...
ps.addBatch(); //加入批處理
})
ps.executeBatch();//執行批處理
conn.commit();
} catch (SQLException e) {
conn.rollback();
System.err.println(String.format("SQLException: Message[%s];SQLState[%s];ErrorCode[%s]", e.getMessage(), e.getSQLState(), e.getErrorCode()));
} finally {
if(ps != null){
ps.close();
}
}
}
}
輸出的例外資訊:
SQLException: Message[Error];SQLState[null];ErrorCode[0]
求大神答疑
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/70790.html
標籤:開發
下一篇:急!!求助!!oracle11g rac 總是有Fatal NI connect error 12170 怎么解決
