JDBI has @SqlCall
annotation for calling procedure, but right now the method marked by this annotation only can return null
or OutParameters
.
So right now is there anyway we can get the out parameter via OutParameters
when calling the procedure with out parameter like below:
CREATE PROCEDURE get_total (IN num1 INT, IN num2 INT, OUT result INT)
BEGIN
SELECT num1 + num2 INTO result;
END;
So right now my temporary solution is:
@SqlCall("call get_total(:num1, :num2, @result)")
public abstract void getTotal(@Bind("num1") int num1, @Bind("num2") int num2);
@SqlQuery("SELECT @result AS result")
public abstract int getQueryTotal();
/**
* call procedure firstly, then query the out parameter as a variable.
*/
public int getCalculateTotal(int num1, int num2) {
getTotal(1, 2);
return getQueryTotal();
}
So is there anyone has a good way to get the out parameters?
You can register an out parameter with the @OutParameter
annotation:
@SqlCall("call get_total(:num1, :num2, :result)")
@OutParameter(name="result", sqlType=Types.INTEGER)
public abstract OutParameters getTotal(@Bind("num1") int num1, @Bind("num2") int num2);
The OutParameters
type has methods to get each out-parameter by name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With