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> |