1.务必关掉自动提交

增强执行效率

  1. conn.setAutoCommit(false);

2.executeBatch失效问题

<1>务必将语句pstmt = conn.prepareStatement(sql);放到循环体外,否则只能插入一条语句

  1. <pre name="code" class="java">      int size = ipAdressList.size();
  2. try {
  3. conn = JdbcUtil.getConnection();
  4. conn.setAutoCommit(false);
  5. pstmt = conn.prepareStatement(sql);
  6. for (int i = 0; i < size; i++) {
  7. //  pstmt = conn.prepareStatement(sql);只能插入最后一条
  8. ipAd = ipAdressList.get(i);
  9. int index = 1;
  10. pstmt.setObject(index++, ipAd.getadress());
  11. pstmt.setObject(index++, ipAd.getPort());
  12. pstmt.setObject(index++, ipAd.getSpeed());
  13. pstmt.setObject(index++, ipAd.getCountry());
  14. pstmt.setObject(index++, ipAd.getProvince());
  15. pstmt.setObject(index++, ipAd.getCity());
  16. pstmt.setObject(index++, ipAd.getIsp());
  17. pstmt.setObject(index++, ipAd.isDomestic());
  18. pstmt.setObject(index++, ipAd.isAlive());
  19. pstmt.addBatch();
  20. }
  21. pstmt.executeBatch();
  22. conn.commit();
  23. } catch (Exception e) {
  24. e.printStackTrace();
  25. }finally {
  26. JdbcUtil.close(rs, stmt, pstmt, conn);
  27. }</pre><br><br>

<2>务必最后提交

    1. conn.commit();

执行Batch批处理遇到的问题的更多相关文章

  1. Spring Batch 批处理框架

    <Spring Batch 批处理框架>基本信息作者: 刘相 出版社:电子工业出版社ISBN:9787121252419上架时间:2015-1-24出版日期:2015 年2月开本:16开页 ...

  2. 图书简介:Spring Batch批处理框架

    大数据时代批处理利器,国内首度原创解析Spring Batch框架. 内容简介: <Spring Batch 批处理框架>全面.系统地介绍了批处理框架Spring Batch,通过详尽的实 ...

  3. spring batch批处理框架学习

    内如主要来自以下链接: http://www.importnew.com/26177.html http://www.infoq.com/cn/articles/analysis-of-large-d ...

  4. Spring Batch 批处理框架介绍

    前言 在大型的企业应用中,或多或少都会存在大量的任务需要处理,如邮件批量通知所有将要过期的会员,日终更新订单信息等.而在批量处理任务的过程中,又需要注意很多细节,如任务异常.性能瓶颈等等.那么,使用一 ...

  5. Spring Batch 批处理原则与建议

    Spring Batch 批处理原则与建议 当我们构建一个批处理的过程时,必须注意以下原则: 通常情况下,批处理的过程对系统和架构的设计要够要求比较高,因此尽可能的使用通用架构来处理批量数据处理,降低 ...

  6. [源码解析] PyTorch 分布式(16) --- 使用异步执行实现批处理 RPC

    [源码解析] PyTorch 分布式(16) --- 使用异步执行实现批处理 RPC 目录 [源码解析] PyTorch 分布式(16) --- 使用异步执行实现批处理 RPC 0x00 摘要 0x0 ...

  7. 批处理(Batch)---批处理脚本。

    批处理(Batch),也称为批处理脚本.顾名思义,批处理就是对某对象进行批量的处理,通常被认为是一种简化的脚本语言,它应用于DOS和Windows系统中.批处理文件的扩展名为bat .目前比较常见的批 ...

  8. 跑批 - Spring Batch 批处理使用记录

    根据spring官网文档提供的spring batch的demo进行小的测验 启动类与原springboot启动类无异 package com.example.batchprocessing; imp ...

  9. 配置 Spring Batch 批处理失败重试机制

    1. 引言 默认情况下,Spring批处理作业在执行过程中出现任何错误都会失败.然而有些时候,为了提高应用程序的弹性,我们就需要处理这类间歇性的故障. 在这篇短文中,我们就来一起探讨 如何在Sprin ...

随机推荐

  1. MyBatis整合Spring MVC

    前面几篇文章已经讲到了mybatis与spring 的集成.目前主流的Web MVC框架,除了Struts这个主力外,还有Spring MVC,主要是由于 Spring MVC 配置比较简单,使用起来 ...

  2. e835. 使JTabbedPane中的卡片生效和失效

    By default, all new tabs are enabled, which means the user can select them. A tab can be disabled to ...

  3. tpshop防止sql注入补丁

    本补丁 由 QQ 木偶人  提供 首先在  www\Application\Common\Common\function.php 文件添加一个方法 /** * 转换SQL关键字 * * @param ...

  4. Git -- 相关命令

    git init : 将当前目录变成Git可以管理的仓库 git add :告诉Git,把文件添加到仓库 git commit -m "" :把文件提交到仓库 git status ...

  5. Eclipse中创建Maven项目失败

    Eclipse中创建Maven项目报错:Unable to create project from archetype org.apache.maven.archetypes:maven-archet ...

  6. Android开源库项目集锦

    一.兼容类库 ActionBarSherlock : Action Bar是Android 3.0后才開始支持的,ActionBarSherlock是让Action Bar功能支持2.X后的全部平台. ...

  7. python_装饰器模式

    装饰器模式定义:动态地给一个对象添加一些额外的职责. 在Python中Decorator mode可以按照像其它编程语言如C++, Java等的样子来实现,但是Python在应用装饰概念方面的能力上远 ...

  8. ASP.NET 网站超时跳转到登录界面

    利用actionFilter过滤器实现,超时跳转到登录界面 /// <summary> /// 登录超时跳转至登录界面 /// </summary> public class ...

  9. js 创建多行字符串

    function heredoc(fn) { ,-).join('\n') + '\n' } var tmpl = heredoc(function(){/* !!! 5 html include h ...

  10. table中td的内容换行。

    table设置样式: table-layout: fixed; td设置: word-wrap: break-word;