我是jdbc的新手我的程序总是返回0.0 ...帮助
CallableStatement cs= con.prepareCall("{ call getbalance(?,?) }");
cs.setInt(1, 1234);
//cs.setString(2, "dfdf");
cs.registerOutParameter(2, Types.DOUBLE,23);
cs.execute();
System.out.println("Balance is "+ cs.getDouble(2));
CREATE PROCEDURE `getbalance`( acno int, out amt int)
begin
select bal * amt from bank WHERE accno=acno;
end;
答案 0 :(得分:1)
设置参数时,帐号是多少?是1还是1234?
cs.setInt(1, 1234);
您输入的内容可能没有记录...
您已键入,
select bal * amt from bank WHERE accno=acno;
如果您同时拥有输入和输出参数
,则不应该是以下情况select bal INTO amt from bank WHERE accno=acno;
编辑的SP将是:
CREATE PROCEDURE `getbalance`( IN acno int, OUT amt int)
AS
BEGIN
SELECT bal INTO amt FROM bank WHERE accno=acno;
END;
答案 1 :(得分:1)
我认为你需要这个,将值设置为amt变量。
Set amt = (select bal * amt from bank WHERE accno=acno);