参数号2不是OUT参数

时间:2013-10-15 11:26:19

标签: java mysql sql stored-procedures callable-statement

String sqlString = "{CALL MyStoredProcedure(?,?)}";

CallableStatement sqlStm = connection.prepareCall(sqlString);

sqlStm.setString(1, username);
sqlStm.registerOutParameter(2, Types.DECIMAL, 0); // <---- ERROR
sqlStm.execute();

这是我的错误堆栈跟踪:

java.sql.SQLException: Parameter number 2 is not an OUT parameter
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
    at com.mysql.jdbc.CallableStatement.checkIsOutputParam(CallableStatement.java:690)
    at com.mysql.jdbc.CallableStatement.registerOutParameter(CallableStatement.java:1881)
    at com.mysql.jdbc.CallableStatement.registerOutParameter(CallableStatement.java:1890)
    at com.isb.igt.database.StoredProcedures.preparationCalls(StoredProcedures.java:40)
    at com.isb.igt.database.StoredProcedures.main(StoredProcedures.java:236)

程序第一行:

  

CREATE DEFINER=devel@11.22.33.44程序MyStoredProcedure(登录时)   VARCHAR(255),OUT变量DECIMAL(20,2)

我无法弄清楚如何让它发挥作用。

谢谢

1 个答案:

答案 0 :(得分:2)

函数调用应该看起来像{? = call MyStoredProcedure(?)}