标题中的内容差不多,应该怎么做?

基本上,我需要将空(空?)引用游标作为IN参数传递给存储过程。

/** spring's PreparedStatementSetter#setValues(...) */
public void setValues(PreparedStatement ps) throws SQLException {
    CallableStatement cs = (CallableStatement) ps;
    cs.setString(1,"constant");
    //this is the IN param
    cs.setNull(2, OracleTypes.CURSOR);
    //this is the OUT param
    cs.registerOutParameter(3, OracleTypes.CURSOR);
}


这失败了:

caused by: java.sql.SQLException: Unsupported feature: sqlType=-10
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
    at oracle.jdbc.driver.OraclePreparedStatement.setNullCritical(OraclePreparedStatement.java:4399)
    at oracle.jdbc.driver.OraclePreparedStatement.setNullInternal(OraclePreparedStatement.java:4161)
    at oracle.jdbc.driver.OracleCallableStatement.setNull(OracleCallableStatement.java:4472)


我在这里不知所措,尝试了几种不同的方法来执行此操作,但是我找不到有关此的任何示例,也不知道如何正确执行此操作。

最佳答案

我的Java有点生锈,但是您应该能够在PL / SQL块中初始化REF CURSOR变量:

String statement = "DECLARE\n" +
                       "l_cursor SYS_REFCURSOR;\n" +
                   "BEGIN\n" +
                       "your_procedure(?, l_cursor, ?);\n" +
                   "END;"
CallableStatement cs = yourConnection.prepareCall(statement);
// bind first and last parameter
cs.setString(1,"constant");
cs.registerOutParameter(2, OracleTypes.CURSOR);

关于java - JDBC CallableStatement和Oracle SYS_REFCURSOR IN参数?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2673626/

10-11 02:45