我正在研究这个jsp项目,出于顾问告诉我们使用准备好的声明,因为它比sql语句安全。但他在mysql记录插入状态中提到它。
wHEN我使用select mysql选择查询我通常用于语句。但是,随着新的想法,我更愿意准备发言。两者都工作得很好。
还有什么是最好的事情。
当使用声明..
什么是最准确的;声明VS准备好的声明
try{
Resultset rs2 = dbCon.createStatement().executeQuery("select max(grn_id) from grn");
if (rs2.first()) {
int grn_id = rs2.getInt(1);
}
catch(Exception e){
e.printstacktrace();
}
当使用事先准备好的声明..
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
String sql = "select * from item where name=?";
try {
con = db.getConnection();
ps = con.prepareStatement(sql);
ps.setString(1, name);
rs = ps.executeQuery();
while (rs.next()) {
int grn_id = rs.getInt(1);
}catch(Exception e){
e.printstacktrace();
}
谢谢。
也不是“更准确”。他们都服从相同的语义。 – EJP
@EJP但他们说准备好的声明对安全性有好处。对? –