我在 DB2 中创建了一个 PLSQL 函数并尝试使用 java 执行它。但是我收到一个错误代码 -440,说明没有找到匹配的存储过程。请参阅下面的代码片段。
Java 代码
Connection dbConnection = null;
CallableStatement callableStatement = null;
try {
dbConnection = getDBConnection();
dbConnection.setAutoCommit(false);
String getDBUSERByUserIdSql = "{? = call saju_func(?,?)}";
callableStatement = dbConnection.prepareCall(getDBUSERByUserIdSql);
callableStatement.registerOutParameter(1, java.sql.Types.INTEGER);
callableStatement.registerOutParameter(3, java.sql.Types.INTEGER);
callableStatement.setInt(2, 10);
callableStatement.setInt(3, 20);
// execute getDBUSERByUserId store procedure
callableStatement.executeUpdate();
int sum = callableStatement.getInt(1);
System.out.println(sum);
dbConnection.commit();
} catch (SQLException e) {
dbConnection.rollback();
System.out.println(e.getMessage());
} finally {
if (callableStatement != null) {
callableStatement.close();
}
if (dbConnection != null) {
dbConnection.close();
}
}
}
PLSQL 函数
CREATE OR REPLACE FUNCTION saju_func (
s_num1 IN NUMBER,
s_num2 IN OUT NUMBER )
RETURN NUMBER
IS
BEGIN
s_num2:= (s_num1+s_num2);
RETURN s_num2;
END saju_func;
/
我尝试了类似的程序(相同的代码没有返回)并且工作正常。