Java/ibatis

[Database/ibatis] 일괄처리

양승길 2016. 8. 24. 08:37

[Database/ibatis] 일괄처리


대량의 데이터에 대하여 insert와 update의 속도를 높히는 목적으로 사용한다.

일괄처리하는 작업도중 delete method와 같은 중간의 결과를 알 수 없음.

수많은 데이터를 작업하게 되면 메모리에 부담이 있음.


startBatch()

https://ibatis.apache.org/docs/java/user/com/ibatis/sqlmap/client/SqlMapExecutor.html#startBatch()


executeBatch()

https://ibatis.apache.org/docs/java/user/com/ibatis/sqlmap/client/SqlMapExecutor.html#executeBatch()


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
try {
    tgtsqlMap.startTransaction();
    tgtsqlMap.startBatch();
 
    tgtsqlMap.delete("관련된 SQL문""매개변수");
    
    for (int i = 0; i < "insert 할만큼의 작업 수"; i++) {
        tgtsqlMap.insert("관련된 SQL문""집어넣을 VO");
    }                    
    
    tgtsqlMap.executeBatch();
    tgtsqlMap.commitTransaction();
    
catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    System.out.println("\nDB Exception appeared. all ongoing datas were rollbacked");
}finally {
    try {
        tgtsqlMap.endTransaction();
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
 
cs


'Java > ibatis' 카테고리의 다른 글

[Database/ibatis] iBatis – Basic Meta Data  (0) 2016.11.06
[Database/ibatis] Only JDBC  (0) 2016.11.06