[英]JDBI supports stored procedure with out parameter
JDBI has @SqlCall
annotation for calling procedure, but right now the method marked by this annotation only can return null
or OutParameters
. JDBI具有用于调用过程的
@SqlCall
注释,但是现在由此注释标记的方法只能返回null
或OutParameters
。
So right now is there anyway we can get the out parameter via OutParameters
when calling the procedure with out parameter like below: 所以现在我们可以通过
OutParameters
获取out参数,当调用带有out参数的过程如下所示:
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: 您可以使用
@OutParameter
注释注册out参数:
@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. OutParameters
类型具有通过名称获取每个out-parameter的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.