자바 호출 저장 과정 에서[반환 매개 변수]와[결과 집합]을 동시에 가 져 옵 니 다.
다음 코드 를 실행 하고 오 류 를 보고 합 니 다.
String querySQL = "{?=call p_sys_manager_csReport(?,?,?,?,?)}";
cstmt = conn.prepareCall(querySQL);
cstmt.registerOutParameter(1, java.sql.Types.INTEGER);
cstmt.setInt(2, modType);
cstmt.setInt(3, dptId);
cstmt.setInt(4, eplId);
cstmt.registerOutParameter(5, java.sql.Types.VARCHAR);
cstmt.registerOutParameter(6, java.sql.Types.VARCHAR);
rs = cstmt.executeQuery();
if (rs != null) {
if (rs.next()) {
companyTotal = rs.getInt("companyTotal");
}
}
String temp = null;
temp = cstmt.getString(5);//
오류 메시지:
java.sql.SQLException: Output parameters have not yet been processed. Call getMoreResults(). at net.sourceforge.jtds.jdbc.ParamInfo.getOutValue(ParamInfo.java:159) at net.sourceforge.jtds.jdbc.JtdsCallableStatement.getOutputValue(JtdsCallableStatement.java:116) at net.sourceforge.jtds.jdbc.JtdsCallableStatement.getString(JtdsCallableStatement.java:310)
오류 메 시 지 는 출력 결과 파라미터 가 처리 되 지 않 았 기 때문에 결과 집합 이 있 는 지 여 부 를 판단 하기 위해 getMoreResults()방법 을 사용 해 야 합 니 다.
그리고 코드 를 수정 하고 문제 해결:
String querySQL = "{?=call p_sys_manager_csReport(?,?,?,?,?)}";
cstmt = conn.prepareCall(querySQL);
cstmt.registerOutParameter(1, java.sql.Types.INTEGER);
cstmt.setInt(2, modType);
cstmt.setInt(3, dptId);
cstmt.setInt(4, eplId);
cstmt.registerOutParameter(5, java.sql.Types.VARCHAR);
cstmt.registerOutParameter(6, java.sql.Types.VARCHAR);
rs = cstmt.executeQuery();
if (rs != null) {
if(rs.next()) {
companyTotal = rs.getInt("companyTotal");
}
}
String temp = null;
/*
* , rs cstmt.getMoreResults() ,sqlserver output
*/
if (!cstmt.getMoreResults()) {// , , output
temp = cstmt.getString(5);//
}
그 중에서 다음 코드 로 바 뀌 어도 틀 리 지 않 습 니 다.
if (rs != null) {
while(rs.next()) {//if while
companyTotal = rs.getInt("companyTotal");
}
}
String temp = null;
/*
* cstmt.getMoreResults(), if(rs.next()) while(rs.next())
*/
//if (!cstmt.getMoreResults()) {
temp = cstmt.getString(5);//
//}