stmt.executeUpdate(sql);//这句为什么不执行?
public static void test() throws
SQLException{
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
conn = JdbcUtils.getConnection();
stmt = conn.createStatement();
String sql = "UPDATE USERTEST SET MONEY=MONEY-10 WHERE USERID=2";
stmt.executeUpdate(sql);//这句为什么不执行?
sql = "select money from USERTEST WHERE USERID=2";
rs = stmt.executeQuery(sql);
float money = 0.0f;
if (rs.next()) {
money = rs.getFloat("money");
}
if(money > 300)
throw new
RuntimeException("已经超过最大值!");
} finally {
// 6关闭资源
JdbcUtils.free(conn, stmt, rs);
}
}
------解决方案--------------------commit