当前位置:Gxlcms > 数据库问题 > MyBatis Oracle 使用序列批量插入数据库

MyBatis Oracle 使用序列批量插入数据库

时间:2021-07-01 10:21:17 帮助过:4人阅读

  此自己写了想了一种方式,没想到一次测试完全通过。

  大致demo如下 

  1. java 代码 
     1 /**
     2  * 文件名称: InsertBatch
     3  * 内容摘要: 测试 MyBatis 使用序列批量插入
     4  * 创 建 人: sunrise
     5  * 创建日期:2015-6-18 下午9:16:06
     6  * 修改记录1: // 修改历史记录,包括修改日期、修改者及修改内容
     7  *   修改日期:
     8  *   版 本 号:
     9  *   修 改 人:
    10  *   修改内容:
    11  * 修改记录2:…
    12  */
    13 @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false) 
    14 public class InsertBatch extends
    15         SpringTransactionalTestCaseWithAllContextConfiguration {
    16     
    17     private static Logger logger = LoggerFactory.getLogger(InsertBatch.class);
    18     @Autowired
    19     DataComponent dataComponent;
    20     @Test
    21     public void test()
    22     {
    23           
    24           int count = 0;//条数
    25           long starTime;//时间
    26           List<Map<String,String>> list = new ArrayList<Map<String,String>>();
    27           do 
    28           {
    29               Map<String,String> map= new HashMap<String,String>();
    30               map.put("DEPT_NAME","XGY");
    31               list.add(map);
    32               count++;
    33           } while (count<2000);
    34           
    35           logger.info(">>>>>>>>>>>>>>>>>>>>>>>>> star");
    36           starTime = System.currentTimeMillis();
    37           sunrise.insertData("sda.HisDataHandle.xgy", list);
    38           logger.info(">>>>>>>>>>>>>>>> 本次插入:{};耗时:{}",count,
    39                   System.currentTimeMillis()-starTime);
    40           logger.info(">>>>>>>>>>>>>>>>>>>>>>>>> over");    
    41     }
    42 }

     

  2. sql xml 
     
    <!-- 测试sql -->
    <insert id="xgy" parameterType="list"> insert into sunrise( ID, DEPT_NAME ) with t as ( <foreach collection="list" item="item" index="index" separator="union all" > select #{item.DEPT_NAME} DEPT_NAME from dual </foreach> ) select SEQ_sunrise.Nextval,t.DEPT_NAME from t </insert>

     

  3. 日志
    [INFO] 15-06-18 21:32:25,446 [com.sunrise.test.dao.InsertBatch]  - >>>>>>>>>>>>>>>>>>>>>>>>> star
    [INFO] 15-06-18 21:32:25,759 [com.ophiux.test.dao.InsertBatch]  - >>>>>>>>>>>>>>>> 本次插入:2000;耗时:312
    [INFO] 15-06-18 21:32:25,760 [com.sunrise.test.dao.InsertBatch]  - >>>>>>>>>>>>>>>>>>>>>>>>> over

     

  4. 数据库截图
  5. 技术分享

 

MyBatis Oracle 使用序列批量插入数据库

标签:

人气教程排行