In my stored procedure I have the following statement
IF (sdate > sysdate)
THEN
RAISE exec_not_allowed;
returnval := sdate;
END IF;
returnval is IN OUT parameter in my procedure.
In java normally an OUT parameter is fetched by using:
callablestatement.getInt(2);
How can I receive returnval in Java if an exception is raised? The exception error code is captured in the Java SQLException part.
Why are you raising an exception at all in this situation? You should only really raise an exception in two situations:
You’re not doing either of these things, and don’t need to. You just want to stop the code running and “return” (it’s a procedure) your value. In this case I would suggest using
return.returnends the execution of the anonymous block that contains it and, in a procedure, returns “control” to the calling statement. i.e. it fits the bill perfectly.The following code assigns
sdateto youroutparameter before halting the execution of the procedure, using return. “More stuff” will never occur.If you only want to assign
sdatetoreturnvalif the condition is not true then you simply swap round these two lines; maybe taking it out of the if statement to make it more obvious. This is what your code does at the moment as when you raiseexec_not_allowedall execution is stopped.In either case your Java call remains the same. In the first procedure (
my_procedure_one) you’ll getsdatereturned and in the second a null, assuming thatreturnvalhadn’t been previously assigned.