怎么获取PreparedStatement 的最终执行SQL

2024-11-23 08:23:59
推荐回答(2个)
回答1:

自己差磨告看游吵吧。虚明
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);
}
}

回答2:

常氏滚派常有人备模问及如何得到PreparedStatement最终执行的SQL语句;或者如何在控制台输出占位符的真实值.....
http://www.blogjava.net/crazycy/archive/2015/02/03/59581.html
详细可以参歼贺考这个,有图解教程,希望可以帮到你