MyBatis BULK INSERT, bulk delete

Source: Internet
Author: User
Tags bulk insert

MyBatis
BULK INSERT
Int Addbatch (@Param ("list") list<custinfo> list);
<insert id= "Addbatch" parametertype= "Java.util.List" >
INSERT into CUSTINFO (
Serialid,
CUSTID,
INVNM,
Updatetimestamp
)
<foreach collection= "List" item= "Item" separator= "union All" index= "index" >
(SELECT
#{item.serialid, Jdbctype=varchar},
#{item.custid, Jdbctype=varchar},
#{item.invnm, Jdbctype=varchar},
To_timestamp (#{item.updatetimestamp}, ' Syyyy-mm-dd hh24:mi:ss.ff ')
From DUAL
)
</foreach>
</insert>
Bulk Delete
int Delcustinfobatch (@Param ("list") list<custinfo> list);
<update id= "Delcustinfobatch" parametertype= "Java.util.List" >
DELETE from CUSTINFO
WHERE Serialid in
<foreach collection= "List" item= "Item" open= "(" separator= "," close= ")" index= "index" >
#{item.serialid,jdbctype=varchar}
</foreach>
</update>


To do a bulk INSERT database, you first need to know the syntax that the database supports for bulk INSERT. The syntax for bulk inserts for each database is different.
MySQL Insertion
<insert id= "BatchSave" parametertype= "Java.util.List" >
INSERT into table_name
( Id
NAME
)
VALUES
<foreach collection= "List" item= "item" separator= "," >
( #{item.id,jdbctype=varchar},
#{item.name,jdbctype=varchar}
)
</foreach>
</insert>

MyBatis BULK INSERT, bulk delete

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.