문서의 선택한 두 판 사이의 차이를 보여줍니다.
다음 판 | 이전 판 | ||
wiki:java:batch [2020/05/07 17:31] hylee 만듦 |
wiki:java:batch [2023/01/13 18:44] (현재) |
||
---|---|---|---|
줄 1: | 줄 1: | ||
- | ====== | + | ====== |
<WRAP left notice 80%> | <WRAP left notice 80%> | ||
* description : | * description : | ||
줄 16: | 줄 16: | ||
<code java> | <code java> | ||
- | // 수집한 데이터 조회 | + | public class RpCubridinsert |
- | cllctVOs = dbUtil.getCllctSelectList(mode, | + | { |
- | + | --- 생략 --- | |
- | // 수집데이터 갯수 만큼 반복 | + | List< |
- | for(RpCllctVO cllctVO: cllctVOs) | + | |
- | { | + | cllctVOs = dbUtil.getCllctSelectList(mode, |
- | dbUtilCu.insertCllctCubridData(cllctVO); | + | |
- | } | + | |
+ | // 수집데이터 갯수 만큼 반복 | ||
+ | for(RpCllctVO cllctVO: cllctVOs) | ||
+ | { | ||
+ | dbUtilCu.insertCllctCubridData(cllctVO); | ||
+ | } | ||
+ | --- 생략 --- | ||
+ | } | ||
public int insertCllctCubridData(RpCllctVO cllctVO) throws SQLException, | public int insertCllctCubridData(RpCllctVO cllctVO) throws SQLException, | ||
{ | { | ||
줄 38: | 줄 43: | ||
+ " | + " | ||
+ " | + " | ||
- | + " ,등등 생략 | + | + " -- 등등 생략 |
+ " | + " | ||
+ " | + " | ||
줄 44: | 줄 49: | ||
+ " | + " | ||
+ " | + " | ||
- | + " ,등등 생략 | + | + " -- 등등 생략 |
+ " | + " | ||
줄 52: | 줄 57: | ||
pstmt.setInt(1, | pstmt.setInt(1, | ||
- | | + | |
ret = pstmt.executeUpdate(); | ret = pstmt.executeUpdate(); | ||
줄 69: | 줄 74: | ||
<code java> | <code java> | ||
+ | public class RpCubridinsert | ||
+ | { | ||
+ | --- 생략 --- | ||
+ | List< | ||
+ | // 수집한 데이터 조회 | ||
+ | cllctVOs = dbUtil.getCllctSelectList(mode, | ||
+ | // cllctVOs 수집 List 데이터를 가지고 | ||
+ | // insert 모듈 호출 | ||
+ | dbUtilCu.insertCllctCubridData(cllctVOs); | ||
+ | --- 생략 --- | ||
+ | } | ||
+ | // 수집한 데이터 조회 | ||
+ | cllctVOs = dbUtil.getCllctSelectList(mode, | ||
+ | dbUtilCu.cllctBatchData(cllctVOs); | ||
+ | |||
+ | public int insertCllctCubridData(RpCllctVO cllctVO) throws SQLException, | ||
+ | { | ||
+ | DBManagerCu dbm = DBManagerCu.getInstanceCu(); | ||
+ | Connection conn = dbm.getConnection(); | ||
+ | |||
+ | PreparedStatement pstmt = null; | ||
+ | int ret = 0; | ||
+ | String sqlText; | ||
+ | |||
+ | sqlText = " INSERT INTO TB_INSEQCMS_BBS_DATA " | ||
+ | + " ( " | ||
+ | + " | ||
+ | + " | ||
+ | + " | ||
+ | + " | ||
+ | + " | ||
+ | + " | ||
+ | + " | ||
+ | + " | ||
+ | + " | ||
+ | + " | ||
+ | |||
+ | pstmt = conn.prepareStatement(sqlText); | ||
+ | | ||
+ | | ||
+ | for(RpCllctVO cllctVO: cllctVOs) | ||
+ | { | ||
+ | |||
+ | try | ||
+ | { | ||
+ | |||
+ | pstmt.setInt(1, | ||
+ | -- 등등 생략 -- | ||
+ | | ||
+ | // Batch Job으로 모은다. | ||
+ | pstmt.addBatch(); | ||
+ | |||
+ | } | ||
+ | catch(Exception e) | ||
+ | { | ||
+ | e.printStackTrace(); | ||
+ | } | ||
+ | } | ||
+ | // Batch Job으로 모은걸 한번에 실행한다. | ||
+ | pstmt.executeBatch(); | ||
+ | | ||
+ | try { | ||
+ | pstmt.close(); | ||
+ | psFileTmt.close(); | ||
+ | psMariaTmt.close(); | ||
+ | } catch (Exception e2) {e2.printStackTrace(); | ||
+ | |||
+ | try { | ||
+ | connCu.close(); | ||
+ | conn.close(); | ||
+ | } catch (Exception e2) {e2.printStackTrace(); | ||
+ | | ||
+ | | ||
+ | |||
+ | | ||
+ | } | ||
줄 80: | 줄 161: | ||
=== 중요 내용 === | === 중요 내용 === | ||
- | > 내용 인코딩이 UTF-8일 떄 제목 인코딩도 아래처럼 선언해야한다. | + | > addBatch()를 사용하면 |
- | > ex) message.setSubject(MimeUtility.encodeText(consultTitle, | + | |
- | > ' | + | |
- | > ex) catch (MessagingException | UnsupportedEncodingException eME) | + | |
=== 소스 출처 === | === 소스 출처 === | ||
- | > 위 소스는 내부 프로젝트 | + | > 위 소스는 내부 프로젝트 |
- | > K * * (기관), 코 * * * * (기업), H * * * * (대학) 에 모두 적용된 것입니다. | + | |
===== Tip ===== | ===== Tip ===== | ||
+ | > 10만건 이상 List에 올렸다가 한번에 실행하면 오류가 날수도있다. | ||
+ | <code java> | ||
+ | if( (count % 100000) == 0){ | ||
+ | System.out.println(count + "건 처리중" | ||
+ | pstmt.executeBatch(); | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | > for문안에 addBatch() 를 하고 카운터를 늘린다음 10만건이 되면 바로 Batch()를 실행해야한다. | ||
===== Troubleshooting ===== | ===== Troubleshooting ===== | ||
===== Ref ===== | ===== Ref ===== | ||
- | * [[https://blog.mailtrap.io/embedding-images-in-html-email-have-the-rules-changed/# | + | * [[http://ojc.asia/bbs/board.php? |
줄 101: | 줄 187: | ||
- | {{tag> | + | {{tag> |