概述
public static boolean bachInsertData(ListsqlList) {boolean bool = false;
Connection conn= null;
Statement stm= null;try{
conn=MyDAO.getConnection();
conn.setAutoCommit(false);
stm=conn.createStatement();for(String sql : sqlList) {
stm.addBatch(sql);
}
stm.executeBatch();
conn.commit();
bool= true;
}catch(Exception e) {if(e instanceofBatchUpdateException){
BatchUpdateException bException=(BatchUpdateException)e;int[] s =bException.getUpdateCounts();
logger.info("更新失败数据:"+sqlList.get(s.length));if(s.length+1
List sList = sqlList.subList(s.length+1, sqlList.size());
bachInsertData(sList);
}
}else{
e.printStackTrace();try{if (stm != null)
stm.close();
}catch(SQLException ex) {
ex.printStackTrace();
}try{
conn.close();
}catch(SQLException ex) {
ex.printStackTrace();
}
}
}finally{try{if (stm != null)
stm.close();
}catch(SQLException ex) {
ex.printStackTrace();
}try{
conn.close();
}catch(SQLException ex) {
ex.printStackTrace();
}
}returnbool;
}
最后
以上就是悦耳百褶裙为你收集整理的java executebatch_JDBC executeBatch 抛出异常停止的全部内容,希望文章能够帮你解决java executebatch_JDBC executeBatch 抛出异常停止所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复