jdbc 更新数据,后台不报错,数据没有更新

public String addBalance(String membership,double balance){
String mSql = "select * from Member where membership="+membership;
String msg="success";
double oldBalance = 0.0;
con = db.loadConnection();
try {
con.setAutoCommit(false);
pst = con.prepareStatement(mSql);
rs = pst.executeQuery();
while(rs.next()){
oldBalance = rs.getDouble("balance");
}
pst = null;
double czbalance = oldBalance+balance;
String iSql = "update member set balance= "+czbalance+" where membership = '"+membership+"'";
System.out.println(iSql);
pst = con.prepareStatement(mSql);
pst.executeUpdate();
con.commit();
con.setAutoCommit(true);
} catch (SQLException e) {
try {
con.rollback();
} catch (SQLException e1) {
e1.printStackTrace();
}
msg = "error_001";
e.printStackTrace();
}finally{
db.close(null, pst, rs);
}
return msg;
}

如果没有报错,那你把打印出来的sql语句去数据库客户端上执行下, 看看是否成功了。

后台没报错的话。就说明语句有问题。看下membership的值是否是你期望的。
System.out.println(iSql); 后在 数据库上执行一下 看看 是否执行了。
跟着断点走一下,也没准回滚了。

若是sql语句不是很多,不需要用上事务,可以省略con.setAutoCommit(false);,取消自动提交,若是sql语句无误,那可能就是没有提交成功到mysql中