我在 Oracle 中编写了一个函数,它接受一个参数并返回一个计数。存储过程的返回类型是数字。我在 Java 中使用 PrepareCall 方法调用该函数,
public static int checkPreviousLoad(int Id) {
int countPrev = 0;
//Here we run the Function to get the existing count of to be loaded Id. try {
CallableStatement proc_stmt = connection.prepareCall(" {? = call F_CHK_PREVIOUSLOAD(?)}");
proc_stmt.setLong(1, Id);
// Register the type of the return value proc_stmt.registerOutParameter(1, OracleTypes.NUMBER);
// Execute and retrieve the returned value. proc_stmt.execute();
ResultSet rs = (ResultSet) proc_stmt.getObject(1);
rs.next();
countPrev = rs.getInt(1);
System.out.println("the count is: "+countPrev);
rs.close();
proc_stmt.close();
} catch(SQLException e) {
String temp = e.getMessage();
System.out
.println("ERROR: SQL Exception when executing F_CHK_PREVIOUSLOAD \n");
System.err.println("ERROR MESSAGE IS: " + temp);
System.err.println("SQLState: " + e.getSQLState());
}
return countPrev;
}`
这是抛出一个 SQLException。
错误信息是这样的:ERROR: SQL Exception when execution F_CHK_PREVIOUSLOAD
错误消息是:索引处缺少 IN 或 OUT 参数:: 2 SQLState: null
请告诉我哪里出错了。谢谢。