hibernate防止sql注入的方法:
1.使用named parameter方法(在查询字符串中使用:),例如:
usernameString//前台输入的用户名
passwordString//前台输入的密码
//hql语句
String queryString = "from User t where t.username:usernameString and t.password: passwordString";
//执行查询
List result = session.createQuery(queryString)
.setString("usernameString ", usernameString )
.setString("passwordString", passwordString)
.list();
2.使用positional parameter方法(在查询字符串中使用?),例如:
usernameString//前台输入的用户名
passwordString//前台输入的密码
//hql语句
String queryString = "from User t where t.username=? and t.password=?";
//执行查询
List result = session.createQuery(queryString)
.setString(0, usernameString )
.setString(1, passwordString)
.list();