a是int型,b是string
s.executeUpdate("update Account set Balance=Balance+a where AccountID='"+b+"'");
哪里出错了
这样直接写就是
Balance=Balance+a 这个a是字符串 就好比Balance原来是1,a也是1 那它就是Balance=1+a 而不是 Balance = 1+1
应该这样写
Balance=Balance+"+a+" 别用单引号.
s.executeUpdate("update Account set Balance=Balance+a where AccountID='"+b+"'");
->
s.executeUpdate("update Account set Balance=Balance"+a+" where AccountID='"+b+"'");
Balance=Balance+a 这俩都是int 类型吗?不是的话这么加不合适
AccountID='"+b+"'" 注入注入啊。。。
用setString吧
s.executeUpdate("update Account set Balance=Balance+a where AccountID='"+b+"'");
->
s.executeUpdate("update Account set Balance=(Balance+"+a+") where AccountID='"+b+"'");
a在sql字符串内了,没有拼接对,s.executeUpdate("update Account set Balance=Balance+"+a+" where AccountID='"+b+"'");