많은 검색과 노력끝에 답을 보게 되었는데
이런 문제를 고민하는 사람은 벌써 내공이 있을 터,
아시아 게이트 스펙 변경과 관련해서 작업하다가...남긴
관련 실전 코드를 소개합니다.
private Element getLitigation(Element param) throws SQLException {
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmm");
DecimalFormat df = new DecimalFormat("##0");
DecimalFormat rdf = new DecimalFormat("##0.00");
try {
String mid = param.getAttributeValue("MemberID");
String pwd = param.getAttributeValue("Password");
String cn = param.getAttributeValue("Country");
String rid = param.getAttributeValue("ReportID");
String rf = param.getAttributeValue("RequestFor");
StringBuffer sb = new StringBuffer();
sb.append(" EXEC kiscis..up_CR4_13 ? , ? ");
String sql = sb.toString();
con = getConnection();
ps = new LadyBugPreparedStatement(con,sql,logger);
int offt = 0;
String oid = sdf.format(new Date());
ps.setString(++offt,oid);
ps.setString(++offt,rid);
boolean getResultSetNow = ps.execute();
int updateCount = -1;
int recordSet = 0;
Element lg = new Element("Litigation");
while (true) { // handle all in-line results from any procedure
if (getResultSetNow) {
recordSet++;
ResultSet r = ps.getResultSet();
if (r.next() && recordSet == 2) { // 2번째 RecordSet에 관심
Element oca = new Element("OngoingCourtAction");
Element noca = new Element("NumberOfOngoingCourtAction");
noca.addContent(df.format(r.getInt("cnt_ing")));
Element ocata = new Element("TotalAmount");
ocata.setAttribute("type","monetary");
ocata.setAttribute("currency","KRW");
ocata.setAttribute("unit","thousand");
ocata.setText(df.format(r.getLong("tot_ing")));
Element ocatata = new Element("TotalAmountToTotalAssets");
ocatata.setAttribute("type","ratio");
ocatata.setText(rdf.format(r.getDouble("jasan_ing")));
Element ocatatn = new Element("TotalAmountToNetSales");
ocatatn.setAttribute("type","ratio");
ocatatn.setText(rdf.format(r.getDouble("mechul_ing")));
oca.addContent(noca);
oca.addContent(ocata);
oca.addContent(ocatata);
oca.addContent(ocatatn);
Element ll = new Element("LostLawsuit");
Element nll = new Element("NumberOfLostLawsuit");
nll.addContent(df.format(r.getInt("cnt_end")));
Element llta = new Element("TotalAmount");
llta.setAttribute("type","monetary");
llta.setAttribute("currency","KRW");
llta.setAttribute("unit","thousand");
llta.setText(df.format(r.getLong("tot_end")));
Element lltata = new Element("TotalAmountToTotalAssets");
lltata.setAttribute("type","ratio");
lltata.setText(rdf.format(r.getDouble("jasan_end")));
Element lltatn = new Element("TotalAmountToNetSales");
lltatn.setAttribute("type","ratio");
lltatn.setText(rdf.format(r.getDouble("mechul_end")));
ll.addContent(nll);
ll.addContent(llta);
ll.addContent(lltata);
ll.addContent(lltatn);
Element pll = new Element("PartiallyLostLawsuit");
Element npll = new Element("NumberOfPartiallyLostLawsuit");
npll.addContent(df.format(r.getInt("cnt_end2")));
pll.addContent(npll);
Element s = new Element("Summary");
Element nlad = new Element("NumberOfLawsuitAsDefendant");
nlad.addContent(df.format(r.getInt("tot_cnt")));
Element sta = new Element("TotalAmount");
sta.setAttribute("type","monetary");
sta.setAttribute("currency","KRW");
sta.setAttribute("unit","thousand");
sta.setText(df.format(r.getLong("tot_amt")));
Element stata = new Element("TotalAmountToTotalAssets");
stata.setAttribute("type","ratio");
stata.setText(rdf.format(r.getDouble("tot_jasan")));
Element statn = new Element("TotalAmountToNetSales");
statn.setAttribute("type","ratio");
statn.setText(rdf.format(r.getDouble("tot_mechul")));
s.addContent(nlad);
s.addContent(sta);
s.addContent(stata);
s.addContent(statn);
lg.addContent(oca);
lg.addContent(ll);
lg.addContent(pll);
lg.addContent(s);
}
r.close();
}
else {
updateCount = ps.getUpdateCount();
if (updateCount != -1) {
logger.debug("update happend " + updateCount + " times!!");
}
}
if ((!getResultSetNow) && (updateCount == -1))
break; // done with loop
getResultSetNow = ps.getMoreResults(); // go to next return
}
return lg;
}
catch(SQLException se) {
logger.error(printStackTrace(se));
throw se;
}
catch(Exception ex) {
logger.error(printStackTrace(ex));
throw new SQLException(ex.toString());
}
finally {
release(rs,ps,con);
}
}