자바 텍스트파일 만들기
DB에서 select해서 전문형식 텍스트파일로 만들어준다.
try {
// 로그 시작
log.debug("-----------" + this.getClass().getName() + "--------------------");
SimpleDateFormat yearMonthFm = new SimpleDateFormat("yyyyMM");
Calendar cal = Calendar.getInstance();
cal.add(cal.MONTH,-1);
//현재날짜기준 저번달을 구한다.
String beforeDate = yearMonthFm.format(cal.getTime());
String filePath = "D://DT_SAP_"+beforeDate+".txt";
File f = new File(filePath);
FileWriter fw = new FileWriter(f);
BufferedWriter bw1 = new BufferedWriter(fw, 1024);
PrintWriter pw1 = new PrintWriter(bw1);
//혹시모를 파라미터를 추가를 생각해서 map으로 만듬.
ParamMap param = new ParamMap();
param.put("target_month", beforeDate);
// 연동 데이터를 select한다.
List sapInfo = cal_sap_infDao.getCal_sap_infBuParamMap(param);
for(int i=0;i< sapInfo.size(); i++){
Cal_sap_inf cal_sap_inf = (Cal_sap_inf) sapInfo.get(i);
pw1.print(cal_sap_inf.getChit_dlm());
pw1.print("|");
pw1.print(cal_sap_inf.getIf_code());
pw1.print("|");
pw1.print(cal_sap_inf.getIf_seq());
pw1.print("|");
pw1.print(cal_sap_inf.getBukrs());
pw1.print("|");
pw1.print(cal_sap_inf.getBudat());
pw1.print("|");
pw1.print(cal_sap_inf.getBldat());
pw1.print("|");
pw1.print(cal_sap_inf.getBlart());
pw1.print("|");
pw1.print(cal_sap_inf.getBktxt());
pw1.print("|");
pw1.print(cal_sap_inf.getWaers());
pw1.print("|");
pw1.print(cal_sap_inf.getFuser());
pw1.print("|");
pw1.print(cal_sap_inf.getDeptid());
pw1.print("|");
pw1.print(cal_sap_inf.getBschl());
pw1.print("|");
pw1.print(cal_sap_inf.getSaknr());
pw1.print("|");
pw1.print(cal_sap_inf.getNewko());
pw1.print("|");
pw1.print(cal_sap_inf.getSgtxt());
pw1.print("|");
pw1.print(cal_sap_inf.getWrbtr());
pw1.print("|");
pw1.print(cal_sap_inf.getZterm());
pw1.print("|");
pw1.print(cal_sap_inf.getZuonr());
pw1.print("|");
pw1.print(cal_sap_inf.getBvtyp());
pw1.println();
}
pw1.close();
bw1.close();
fw.close();
// 로그 종료
log.debug("-----------" + this.getClass().getName() + " : " + stopWatch.getTotalTimeString() + "--------------------");
// 결과 로그 작성
nowDt= dayTimeFm.format(new Date());
job_exec_log.setResult("S");
job_exec_log.setExec_time(stopWatch.getTotalTimeString());
job_exec_log.setEnd_dt(nowDt);
job_exec_logDao.insertJob_exec_log(job_exec_log);
} catch (SQLException ex) {
// 오류 로그 작성
log.error(this, ex);
try {
nowDt = dayTimeFm.format(new Date());
job_exec_log.setResult("F");
job_exec_log.setExec_time(stopWatch.getTotalTimeString());
job_exec_log.setEnd_dt(nowDt);
job_exec_log.setErr_msg(ex.getMessage().substring(0, 1000));
job_exec_logDao.insertJob_exec_log(job_exec_log);
} catch (SQLException ez) {
}
}
전문형식으로 만들었음..
쿼리는 간단하게 컬럼크기에 맞게 데이터+공백으로 처리..
SELECT
RPAD(target_month,6,' ') AS target_month,
RPAD(nvl(if_code, ' '),5,' ') AS if_code
FROM cal_sap_inf
WHERE target_month = #target_month#
반응형
'Java' 카테고리의 다른 글
[Java] 평일 날짜 수(근무일) 계산 (0) | 2020.03.17 |
---|---|
[Java] SHA-256 암호화 예제 (0) | 2020.02.05 |
[Mybatis] mapUnderscoreToCamelCase 설정 (0) | 2019.05.14 |
[Java] java.security.InvalidKeyException: Illegal key size 해결 방안(자바 암호화 모듈 JEC) (1) | 2019.01.08 |
[ibatis] 자바 프로시저 호출 (0) | 2018.09.21 |