Java provides CallableStatements for such purposes.
CallableStatement cstmt = conn.prepareCall("{? = CALL total_cancellations()}"); cstmt.registerOutParameter(1, Types.INTEGER); cstmt.setInt(2, acctNo); cstmt.executeUpdate(); int cancel= cstmt.getInt(1); System.out.print("Cancellation is "+cancel);
prints the same as in pl / sql. According to the docs of Connection#prepareCall() ,
Creates a CallableStatement object to invoke database stored procedures. The CallableStatement object provides methods for setting its IN and OUT parameters and methods for making a call to a stored procedure.
You can also pass parameters to a function. for ex,
conn.prepareCall("{? = CALL total_cancellations(?)}"); cstmt.setInt(2, value);
will pass the values โโof the function as an input parameter.
Hope this helps!
source share