请问大家sql语句预编译后怎么注入,我目前知道预编译是防止sql注入最有效的方法,但不知道怎么sql预编译后的注入,谢谢大家
你说的应该是PreparedStatement,PreparedStatement本身是防注入的
Connection conn = null;
try {
conn = ConnectionHandler.getConn();
String sql = "INSERT INTO item(id,title,price,sales) VALUES(?,?,?,?)";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1,item.getId());
pstmt.setString(2,item.getTitle());
pstmt.setDouble(3,item.getPrice());
pstmt.setInt(4,item.getSales());
pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
throw new SQLException("新增商品到商品表失败");
}
其实这些网上都可以查得到的,听别人说总是会有可能遗漏的