我正在用 JAVA 制作一个控制台应用程序,我需要在其中执行一个用Oracle制作的存储过程,说存储过程有三个输入变量,它们是字符串数据类型和两个输出变量,其中一个是字符串类型和最后一个是 SYS_REFCURSOR 类型。我遇到的问题是,目前我指出此存储过程将返回给我的数据类型,在 Java 中它无法识别 SYS_REFCURSOR 数据类型。
这是我在 JAVA 中的代码示例:
Connection connection = null;
CallableStatement callableStatement = null;
try {
connection = ConnectionConfiguration.getConecction();
callableStatement = connection.prepareCall("{CALL sp_jobsMonitor_UpdateCurrentSt(?,?,?,?,?)}");
callableStatement.setString(1, job.getJobName());
callableStatement.setString(2, job.getExecutionStatus());
callableStatement.setString(3, job.getExceptionID());
callableStatement.registerOutParameter(4, Types.VARCHAR);
callableStatement.registerOutParameter(5, Types.xxxx);
callableStatement.executeUpdate();
job.setExceptionMessage(callableStatement.getString(4));
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}finally {
if (callableStatement != null) {
try {
callableStatement.close();
} catch (SQLException e) {
return e.getMessage();
}
}
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
return e.getMessage();
}
}
}
return "ok";
在该行callableStatement.registerOutParameter(5, Types.xxxx);
中,我需要指明数据类型 SYS_REFCURSOR。
我已经尝试过指出数据的类型,Types.OTHER
但Types.VARCHAR
我什至不知道我做错了什么或遗漏了什么。
干杯
注意:我使用的数据类型基于 Oracle 数据类型。
JDBC 不支持这些类型的游标,仅通过 Oracle 支持。要解决这个问题,您必须使用 Oracle 输出数据类型:
来源:https ://oracle-base.com/articles/misc/using-ref-cursors-to-return-recordsets