【问题标题】:Calling procedure in java with parameter [closed]使用参数在java中调用过程[关闭]
【发布时间】:2016-05-14 23:30:37
【问题描述】:

我在使用 CallableStatement 时遇到了困难,该参数应更改数据库中的所有薪水。

这是程序。 Ratio 不在 Employee 类中。

    create or replace PROCEDURE CHANGE_SALARY
    (ratio DECIMAL) AS
    BEGIN
    Update employee SET salary=round(salary/ratio);
    end;

找不到如何实施。我需要从“field_getRatio”获取比率并发送到程序以应用所有工资。

    String sql = "{call change_salary(?)}";
    CallableStatement cStmt = dbConnection.prepareCall(sql);
    cStmt.registerOutParameter(1, Types.DECIMAL);
    cStmt.execute();

感谢您的所有帮助。

编辑:不知道为什么这篇文章被点赞,但感谢蒂姆,问题已经解决了。

【问题讨论】:

    标签: java stored-procedures


    【解决方案1】:

    你误解了inout参数。

    这个:

    CallableStatement cStmt = dbConnection.prepareCall(sql);
    cStmt.registerOutParameter(1, Types.DECIMAL);
    cStmt.execute();
    

    声明你的 ratio 参数是过程的输出,但它不是。

    你应该这样做:

    CallableStatement cStmt = dbConnection.prepareCall(sql);
    cStmt.setObject(1, theRatio, Types.DECIMAL);
    cStmt.execute();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-21
      • 2013-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-26
      相关资源
      最近更新 更多