在我们做.net系统的时候,所做的最常见的批量操作就是批量导入、插入、更新、删除等等,以前我们怎么做呢?基本上有以下几种方式:
1、利用循环调用insert方法,一条条插入。
public boolean insertStudent(List<Student> studentList) { try{ if(studentList.count !=0){ for(int i=0;i<studentList.count;i++){ //调用save方法 } return true; } }catch(Exception ex){ throw New Exception("插入失败,请重试!") return false; } }
2、利用循环做sql语句拼接,然后批量执行sql语句。
public boolean insertStudent(List<Student> studentList) { try{ if(studentList.count !=0){ stringBuffer strSqltxt=""; for(int i=0;i<studentList.count;i++){ strSqltxt.append("insert into TableName (……) values (……);" } cmd.executesql(strSqltxt.toString()); } }catch(Exception ex){ throw New Exception("插入失败,请重试!") return false;
【Hibernate框架】批量操作Batch总结
最新推荐文章于 2024-08-05 15:01:49 发布