I created a PLSQL function in DB2 and tried to execute it using java. But I am receiving an error code of -440 stating no matching stored procedure is found. Please see the code snippet below.
Java Code
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 Function
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;
/
I have tried a similar procedure (same code without return) and is working fine.