Reputation: 343
I am getting a 'Cursor state not valid' error when I try to run the stored procedure. The 13th parameter acts as a both IN/ OUT which returns value on both cases but it requires parameter value when its an update. This stored proc works when I try to run in IBM iSerires but fails through java. Not sure what I am missing here. Thanks in advance.
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, "[email protected]");
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;
}
Upvotes: 0
Views: 368