尝试运行存储过程时出现“光标状态无效”错误。第 13 个参数充当两个 IN/OUT,在两种情况下都返回值,但在更新时需要参数值。当我尝试在 IBM iSerires 中运行但通过 java 失败时,此存储过程有效。不知道我在这里缺少什么。提前致谢。
public String saveContact(Contact payload, Context cntx, String contactType) {
Connection connection = null;
String headerKey = null;
try {
connection = ds.getConnection();
CallableStatement callable = invokeStoredProc(connection, payload, contactType);
ResultSet rs = callable.executeQuery(); //ERRORS OUT HERE
while (rs.next()) {
headerKey = rs.getString(13);
}
String output = callable.getString(14);
if(!_helper.containsValue(output)){
logger.error("WISE Stored proc execution results an errorCode: " + output.trim());
}
callable.close();
} catch (Exception e) {
logger.error("Exception here. {}", e.getMessage());
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
logger.error("closing database connection: {} ", e.getMessage());
}
}
return headerKey;
}
public CallableStatement invokeStoredProc(Connection connection, Contact payload, String contactType) throws Exception {
logger.info("Calling WISE stored proc through invokeWISECustomerContactStoredProc()");
CallableStatement call = connection.prepareCall("{CALL CONTACT_SP(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}");
if(Constants.CONTACT_PROCESS_UPDATE.equalsIgnoreCase(contactType)){
logger.info("Contact already exists. Set to update it");
call.setString(1, "UPDATE");
call.registerOutParameter(13, Types.CHAR);
call.setString(13, "345");
}else{
logger.info("Set to save the new contact.");
call.setString(1, "ADD");
call.registerOutParameter(13, Types.CHAR);
call.setString(13, "");
}
call.setString(1, "ADD");
call.setString(2, "00345");
call.setString(3, "000245");
call.setString(4, "Mr");
call.setString(5, "Mark");
call.setString(6, "T");
call.setString(7, "Taylor");
call.setString(8, "taylor@yahoo.com");
call.setString(9, "9375551456");
call.setString(10, "9375551789");
call.setString(11, "9375551345");
call.setString(12, "MarkT02");
call.setString(14, "");
call.registerOutParameter(14, Types.CHAR);
return call;
}