java - 来自 java 的存储过程调用抛出“游标状态无效”错误
问题描述
尝试运行存储过程时出现“光标状态无效”错误。第 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;
}
解决方案
推荐阅读
- linux - 如何尾随所有文件并通过通配符名称排除某些文件?
- firebird - 为什么 Firebird 2.5.8 在 SELECT CURRENT_ROLE 上返回 NONE?
- reactjs - 单击按钮后在 Jest 中测试函数调用(模拟 fetch 调用)
- excel - 循环遍历变体数组时不能使用具有多个条件(AND/OR)的 If 语句?
- java - spring jpa 存储库在哪里存储数据?
- google-apps-script - 如何将访问权限限制为仅一个电子表格,而不是从用户应用脚本访问所有电子表格
- docker - Azure 管道:Docker buildAndPush 失败
- jupyter-notebook - JupyterLab:将笔记本移动到新位置后无法加载文件
- scala - Scala 上下文限制了抽象类型参数的“模仿”
- c# - 如何使用 GridUnitType.Star 在网格长度上执行动画?