0

我正在尝试将列的值减少一些。换句话说,该列是 double 类型,我想将其减少“总”数量。如果初始值是 100,那么现在它必须是 100-total。这是我的代码:

PreparedStatement checkDB1 = (PreparedStatement) con.prepareStatement("update accounts set balance=balance-? where iban=?");
checkDB1.setString(1, total);

这给出了一个语法错误:

 reason: actual argument double cannot be converted to String by method invocation conversion

那么我该如何编写这个查询呢?谢谢

4

1 回答 1

2

唯一的错误是用于设置PreparedStatement参数的类型不正确,如错误消息所示

PreparedStatement checkDB1 = 
       con.prepareStatement("update accounts set balance=balance - ? where iban=?");
checkDB1.setDouble(1, total);
            ^^^

另请注意,PreparedStatement演员已被删除,因为不必要

于 2013-07-11T12:16:28.097 回答