开发者

How to set INOUT parameters from frontend while calling a stored procedure

I developed a SP, say abc(a,b,c), where

  • a is IN parameter
  • b is OUT parameter
  • c is INOUT parameter.

If i call this sp directly from the DB as abc(<val>,?,?), I get开发者_Go百科 err

The number of variables in the EXECUTE statement, the number of variables in the OPEN statement, or the number of arguments in an OPEN statement for a parameterized cursor is not equal to the number of values required.

But if i run it as abc(<val>,?,<val>), it runs successfully.

I want to call this SP through Java program. For this, i am setting IN & INOUT parameters. And registering OUT & INOUT parameters. But it is giving me the same error as above


Pl read CallableStatements and INOUT Parameters


You need to use java.sql.CallableStatement to process out parameters.

So, following your example, your call would be:

String sql = "{ call abc(?, ?, ?) }";
CallableStatement cs = conn.prepareCall(sql);
cs.setInt(1, 20); // setting "a" in parameter to 1
cs.registerOutParameter(2, Types.VARCHAR); // setting "b" as out parameter
cs.setString(3, "Some String"); // setting "c" as in parameter
cs.registerOutParameter(3, Types.VARCHAR); // setting "c" as out parameter
// then execute
cs.executeUpdate();
// and retrieve out parameters
String bout = cs.getString(2);
String cout = cs.getString(3);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜