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;
}
jdbc 更新数据,后台不报错,数据没有更新
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-