org.hibernate.session 准备好的语句
org.hibernate.session prepared statement
一定有办法在休眠状态下准备我们的 SQL 查询吗?
所以我们不会以易受 SQL 此类注入攻击的代码告终...
public List<Book> findByAutor(String author) {
String qry = "from Book where author=\'"+author+"\'";
@SuppressWarnings("unchecked")
List<Book> books = (List<Book>) getCurrentSession().createQuery(qry).list();
return books;
}
因为用户可以输入如下内容:
"Paulo Coelho\' or ''='"
作为作者获取我们数据库中的所有书籍...
可能是一些简单的东西,但我在互联网上找不到它:/
尝试使用这样的东西,你可以 set
字符串和 check
它:
String qry = "from Book where author= ?";
@SuppressWarnings("unchecked")
List<Book> books = (List<Book>) getCurrentSession().createQuery(qry)
.setString(0, author)
.list();
有关详细信息,请查看此 link
一定有办法在休眠状态下准备我们的 SQL 查询吗?
所以我们不会以易受 SQL 此类注入攻击的代码告终...
public List<Book> findByAutor(String author) {
String qry = "from Book where author=\'"+author+"\'";
@SuppressWarnings("unchecked")
List<Book> books = (List<Book>) getCurrentSession().createQuery(qry).list();
return books;
}
因为用户可以输入如下内容:
"Paulo Coelho\' or ''='"
作为作者获取我们数据库中的所有书籍...
可能是一些简单的东西,但我在互联网上找不到它:/
尝试使用这样的东西,你可以 set
字符串和 check
它:
String qry = "from Book where author= ?";
@SuppressWarnings("unchecked")
List<Book> books = (List<Book>) getCurrentSession().createQuery(qry)
.setString(0, author)
.list();
有关详细信息,请查看此 link