自己差磨告看游吵吧。虚明
public void update(User u) {
Connection conn = null;
PreparedStatement stmt = null;
String sql = "update t_user set uname=?,upwd=?,addNum=? where id = ?";
try {
conn = ConnectionUtils.getConnection();
stmt = conn.prepareStatement(sql);
stmt.setString(1, u.getUname());
stmt.setString(2, u.getUpwd());
stmt.setInt(3, u.getAddNum());
stmt.setInt(4, u.getId());
stmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally{
ConnectionUtils.close(stmt);
ConnectionUtils.close(conn);
}
}
常氏滚派常有人备模问及如何得到PreparedStatement最终执行的SQL语句;或者如何在控制台输出占位符的真实值.....
http://www.blogjava.net/crazycy/archive/2015/02/03/59581.html
详细可以参歼贺考这个,有图解教程,希望可以帮到你