I found a problem when updating the data in the database. The log shows update successfully, but the data in the database does not change. this happens sometimes, not frequently, like 1 of 200.
below is the code:
public void updateRecharge(String serial_num, String msg, String succ_amout, String datetime) {
try {
con = open();
} catch(Exception e) {
e.printStackTrace();
log.writeLog(serial_num, datetime, "fail to update: " + e.getMessage());
return;
}
String area = new JudgeTidField().checkTidField(serial_num)[1];
String table = new JudgeTidField().table(area);
String query = "update " + table + " set Recharge_state=?, Recharge_money=?, Recharge_record_date=? where Serial_number='" + serial_num + "';";
try {
preState = con.prepareStatement(query);
preState.setString(1, msg);
preState.setFloat(2, Float.valueOf(succ_amout));
preState.setString(3, datetime);
preState.executeUpdate();
log.writeLog(serial_num, datetime, "success to update");
} catch(Exception e) {
e.getMessage();
log.writeLog(serial_num, datetime, "fail to update: " + e.getMessage());
} finally {
try {
preState.close();
} catch (SQLException e1) {
e1.printStackTrace();
}
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
I check the log, it shows "success to update", but the data does not change. what kind of problem cause this happening?
?forserial_numlike the other parameters; 2-preState.executeUpdate();returns aintvalue representing the number of the rows updated, you might want to check it