Reputation: 361
I am a newbie to jdbc my program always return 0.0... help
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;
Upvotes: 0
Views: 83
Reputation: 14361
For setting the parameters, what is the account number? Is it 1 or 1234?
cs.setInt(1, 1234);
You may not have a record with the acno you are inputting...
You have typed,
select bal * amt from bank WHERE accno=acno;
Shouldn't it be the following, given you have both input and output parameters
select bal INTO amt from bank WHERE accno=acno;
the edited SP would be:
CREATE PROCEDURE `getbalance`( IN acno int, OUT amt int)
AS
BEGIN
SELECT bal INTO amt FROM bank WHERE accno=acno;
END;
Upvotes: 1
Reputation: 27427
I think you need this, set value to amt variable.
Set amt = (select bal * amt from bank WHERE accno=acno);
Upvotes: 1