【发布时间】:2021-10-23 01:39:43
【问题描述】:
如果我们在 SQL 查询中传递 1=1,它将返回所有数据,因为它在所有条件下都为真。
String query = "select * from users where userId= 'abcd' or '1'='1'";
我正在研究 PreparedStatement 接口,发现 setString 方法将列的值附加到准备语句。我想知道内部它是如何防止 sql 注入的?如果我通过这样的事情 -
Connection con=DriverManager.getConnection(url,username,password);
PreparedStatement query = con.prepareStatement("select * from users where userId=?");
query.setString(1,userId);'
【问题讨论】: