MyBatis Oracle BULK INSERT database using sequences

Source: Internet
Author: User
Tags bulk insert

since the project last night batch job extraction data primary key generator problem, emergency resolution with sequence as the primary key.

The underlying uses MyBatis to interact with the Oracle database library. she talked with her for a long time and she didn't give a solution. to be

This himself wrote a way of thinking, and did not expect a test to pass completely.

The approximate demo is as follows  

  1. Java code
    1 /**2 * File name: Insertbatch3 * Content Summary: Test MyBatis Using series BULK INSERT4 * Create person: Sunrise5 * Date Created: 2015-6-18 pm 9:16:066 * Modify record 1://Modify history, including date of modification, modified by, and modified content7 * Date Modified:8 * Version number:9 * Modify Person:Ten * What to modify: One * Change record 2: ... A  */ -@TransactionConfiguration (TransactionManager = "TransactionManager", Defaultrollback =false)  -  Public classInsertbatchextends the springtransactionaltestcasewithallcontextconfiguration { -      -     Private StaticLogger Logger = Loggerfactory.getlogger (insertbatch.class); - @Autowired + datacomponent datacomponent; - @Test +      Public voidTest () A     { at            -           intCount = 0;//article number -           LongStartime;//Time -list<map<string,string>> list =NewArraylist<map<string,string>>(); -            Do  -           { inMap<string,string> map=NewHashmap<string,string>(); -Map.put ("Dept_name", "Xgy"); to list.add (map); +count++; -} while(count<2000); the            *Logger.info (">>>>>>>>>>>>>>>>>>>>>>>> > Star "); $Startime =System.currenttimemillis ();Panax NotoginsengSunrise.insertdata ("SDA. Hisdatahandle.xgy ", list); -Logger.info (">>>>>>>>>>>>>>>> this insert: {}; time-consuming: {}", Count, theSystem.currenttimemillis ()-startime); +Logger.info (">>>>>>>>>>>>>>>>>>>>>>>> > Over ");  A     } the}

  2. SQL XML
     
    <!--test SQL--
    <InsertID= "Xgy"ParameterType= "List">INSERT INTO Sunrise (ID, dept_name) with t a S (<foreachCollection= "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. Log
    [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]  ->>>>>>>>>>>>>>>> This insert: 2000; time: 312[info] 15-06-18 21:32:25,760 [Com.sunrise.test.dao.InsertBatch]  ->>>>>>> >>>>>>>>>>>>>>>>>> over

  4. Database

MyBatis Oracle BULK INSERT database using sequences

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.