`
weishuwei
  • 浏览: 322177 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

ibatis的批处理

阅读更多

ibatis的批处理

(1)spring模式:尽管spring已经配置了事务,但以下代码中还是要设置事务,不然batch不会起作用;另外这里虽然设了一下事务处理,但对全局事务并不会造成影响;
注:不启用事务将建立多次连接,这表示batch没起作用,建立事务后一次连接就搞定了.
public void batchAddExamlog(List examlogList) throws SQLException{                
    SqlMapClient smc=this.getSqlMapClient();                                        
    try {                                                                           
        smc.startTransaction();                                                       
        smc.startBatch();                                                             
                                                                                                                                                      
        for (Iterator iter = examlogList.iterator(); iter.hasNext();) {
            Examlog log = (Examlog) iter.next();
            smc.update("insertExamlog", log);
        }                                                                           
        smc.executeBatch();                                                           
    } catch (Exception e) {                                                         
        // TODO: handle exception                                                     
    }finally{                                                                       
        smc.commitTransaction();                                                      
        smc.endTransaction();                                                         
    }                                                                               
}                                                                                 

(2)直接采用回调函数设置                                                                             
public void batchAddExamlog2(List examlogList){                                   
    getSqlMapClientTemplate().execute(new SqlMapClientCallback() {                  
        public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
         executor.startBatch();                                                     
         executor.update("insertSomething", "myParamValue");                        
         executor.update("insertSomethingElse", "myOtherParamValue");               
         executor.executeBatch();                                                   
         return null;                                                               
        }                                                                           
      });                                                                           
}

分享到:
评论

相关推荐

    ibatis批处理.doc

    ibatis批处理.doc ibatis批处理.doc

    iBatis批处理

    NULL 博文链接:https://san-yun.iteye.com/blog/900949

    ibatis批处理

    ibatis批量操作存在两种方式: 一种是直接在代码中进行循环操作,另一种是在配置文件中进行循环操作。

    ibatis 完美例子 一对多 批处理 事务 和 spring struts2集成

    ibatis 完美例子 一对多 批处理 事务 和 spring struts2集成 ,一朵多 插入1万条数据,不到2秒,备注不包含类库

    ibatis的两种方式实现批处理.doc

    技术分享:ibatis的两种方式实现批处理

    iBatis SQL Maps开发指南.pdf

    开发指南 iBATIS SQL Maps Page 3 of 62 Map类型的Result 复杂类型属性(即自定义类型的属性) 避免N+1 Select(1:1) 延迟加载 VS 联合查询(1:1) 复杂类型集合的属性 避免N+1 Select(1:M和M:N) 组合键值或多...

    SpringBatch批处理 刘相编

    基本篇重点讲述了数据批处理的核心概念、典型的作业配置、作业步配置,以及Spring Batch框架中经典的三步走策略:数据读、数据处理和数据写,详尽地介绍了如何对CVS格式文件、JSON格式文件、XML文件、数据库和JMS...

    iBATIS 帮助文档

    SQL Maps (com.ibatis.sqlmap.*)......................................................................................................5 SQL Map的概念........................................................

    基于jsp的团购网站

    完完全全可以用的,放心下载! 1、日期控件 ...5、jdbc 批处理 sql 6、各种数据库的分页方法 7、数据库的优化 8、海量数据的处理 9、sql 注入 10、java 设计模式 11、iBatis 使用 12、webservice 13、Hessian

    TCPforScraping

    使用eGovframework,maven,ibatis开发 TCP侦听器,TCP处理程序功能实现 实现专业的解析功能 响应代码,州代码设计和实施 FTP通讯功能实现 传统数据删除批处理功能的实现 常见异常功能的实现 Admin Manager的页面...

    ibator1.2.1配置文件

    自动生成dto\dao\xml 自带批处理自动生成程序

    通向架构师的道路

    自己整理的一位牛人写的通向架构师的道路的博文,对架构师入门很有指导意义,列出章节如下: (第一天)之Apache整合Tomcat ...(第三天)之apache性能调优 ...(第二十七天)IBM网格计算与企业批处理任务架构

Global site tag (gtag.js) - Google Analytics