IBATIS batch inserts data into the Oracle database

Source: Internet
Author: User

This article will introduce iBATIS batch data insertion to the database. I hope this article will help you.

Using callback interfaces in the iBATIS framework also enables batch data operations to reduce the number of accesses to the database and improve performance. The following is an example of batch data insertion into an Oracle database using the iBATIS framework:

Batch Data insertion:

The Code is as follows: Copy code

/**
* Ibatis inserts data in batches.
* @ Param recordList
*/
Public void insertRecordByList (final List <Record> recordList ){
This.getsqlmapclienttemplate(cmd.exe cute (new SqlMapClientCallback (){
Public Object doInSqlMapClient (SqlMapExecutor executor)
Throws SQLException {
Executor. startBatch ();
// Maximum number of entries submitted each time
Final int batchSize = 200;
Int count = 0;
For (Record record: recordList ){
Executor. insert ("Record. insertRecord", record );
// Submit every 200 data entries
If (++ count % batchSize = 0 ){
Executor.exe cuteBatch ();
}
}
// Submit the remaining data
Executor.exe cuteBatch ();
Return null;
}
});
}

Corresponding sqlMap:

The Code is as follows: Copy code

<SqlMap namespace = "Record">
<TypeAlias alias = "record" type = "me. gogogogo. domain. Record"/>

<Insert id = "insertRecord" parameterClass = "record">
Insert into record
(Id,
Record,
InsetDate)
Values
(Sequence_record.nextval,
# Record #,
Sysdate)
</Insert>
</SqlMap>

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.