Java enables bulk insertion of data into Oracle via MyBatis

Source: Internet
Author: User

<?XML version= "1.0" encoding= "UTF-8"?><!DOCTYPE Mapper Public "-//mybatis.org//dtd mapper 3.0//en" "Http://mybatis.org/dtd/mybatis-3-mapper.dtd "><Mappernamespace= "Com.oracle.mapper.AccountInfoMapper"><!--the full class name of the interface -    <!--Type: The full class name of the entity class -    <ResultmapID= "Baseresultmap"type= "Com.oracle.entity.AccountInfo">        <IDcolumn= "ID" Property= "id"Jdbctype= "DECIMAL" />        <resultcolumn= "USERNAME" Property= "UserName"Jdbctype= "VARCHAR" />        <resultcolumn= "PASSWORD" Property= "Password"Jdbctype= "VARCHAR" />        <resultcolumn= "GENDER" Property= "Gender"Jdbctype= "CHAR" />        <resultcolumn= "EMAIL" Property= "Email"Jdbctype= "VARCHAR" />        <resultcolumn= "Create_date" Property= "CreateDate"Jdbctype= "DATE" />    </Resultmap>    <!--the ID is consistent with the method name in the interface -    <SelectID= "Queryallaccountinfo"Resultmap= "Baseresultmap">Select ID, Username,password, GENDER, EMAIL, create_date from Account_info</Select>    <InsertID= "Batchinsertaccountinfo"ParameterType= "Java.util.List">INSERT into Account_info (ID, Username,password,gender, email,create_date) (<foreachCollection= "List"Index=""Item= "AccountInfo"Separator= "UNION All">Select #{accountinfo.id}, #{accountinfo.username}, #{accountinfo.password  }, #{accountinfo.gender}, #{accountinfo.email}, #{accountinfo.createdate} from Dual</foreach>        )    </Insert>        <InsertID= "Batchinsertaccountinfouseseq"ParameterType= "Java.util.List">        <SelectkeyResulttype= "Long"Keyproperty= "id"Order= "Before">SELECT Account_seq. Nextval from dual</Selectkey>INSERT into Account_info (ID, Username,password,gender, email,create_date) SELECT account_seq. Nextval, m.* from (<foreachCollection= "List"Index=""Item= "AccountInfo"Separator= "UNION All">Select #{accountinfo.username}, #{accountinfo.password}, #{accountinfo.ge NDEr}, #{accountinfo.email}, sysdate from dual</foreach>) M</Insert>        <InsertID= "Insertone"ParameterType= "Com.oracle.entity.AccountInfo">        <SelectkeyResulttype= "Long"Keyproperty= "id"Order= "Before">SELECT Account_seq. Nextval from dual</Selectkey>INSERT into Account_info (ID, Username,password,gender, email,create_date) VALUES (#{id}, #{username}, #{password}, #{gender}, #{email}, Sysdate) 
    </Insert></Mapper>

Java enables bulk insertion of data into Oracle via MyBatis

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.