Code Monkey home page Code Monkey logo

Comments (3)

nhkiiim avatar nhkiiim commented on August 30, 2024

PreparedStatement addBatch()

https://docs.oracle.com/javase/7/docs/api/java/sql/Statement.html#addBatch(java.lang.String)

  • PreparedStatement에서 제공하는 addBatch()를 활용하면 쿼리를 실행하지 않고 쿼리 구문을 메모리에 올려두었다가 executeBatch() 시 한번에 배치로 실행 가능
while(...) {
...
// addBatch에 담기
pstmt.addBatch();

// 파라미터 Clear
pstmt.clearParameters() ;

  // 건수를 나눠서 건 단위로 커밋
  if ( (i % 10000) == 0){
  
      // Batch 실행
      pstmt.executeBatch() ;
      
      // Batch 초기화
      pstmt.clearBatch();
      
      // 커밋
      con.commit() ;
  }

}

addBatch 대용량 데이터 처리 참고 : https://fruitdev.tistory.com/111

from til.

nhkiiim avatar nhkiiim commented on August 30, 2024

MyBatis foreach

https://mybatis.org/mybatis-3/ko/dynamic-sql.html#foreach

  • 파라미터를 Collection으로 받아 반목문 형태로 쿼리 작성 가능

오라클 PL/SQL과 foreach를 활용해 적용

<update id="update" parameterType="java.util.List">
    <foreach collection="list" item="dto" open="DECLARE BEGIN" separator=";" close="END;">
        UPDATE [테이블명]
        name = #{dto.name}
        WHERE BLD_ID = #{dto.bldId}
          AND OP_DT = #{dto.optDt}
          AND OP_SEQ = #{dto.opSeq}
    </foreach>
</update>

<foreach> 속성

  • collection : 전달 받은 인자를 속성 값으로 삽입, Map, Array, List, Set 등과 같은 반복 가능한 객체를 전달 가능
  • item : collection 속성에서 전달 받은 객체 이름 지정
  • open : 구문 시작 시 삽일 할 문자열
  • close : 구문 종료 시 삽일 할 문자열
  • separator : 반복되는 구문 사이에 삽일 할 문자열
  • index : index값 이름 지정

from til.

nhkiiim avatar nhkiiim commented on August 30, 2024

오라클 PL/SQL 참고 : https://tantangerine.tistory.com/189

MyBatis에서 Batch처리 - SqlSession과 foreach 비교 : https://yookeun.github.io/java/2015/06/19/mybatis-batch/

from til.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.