我正在開發一個使用hibernate的應用程序。當我嘗試創建一個登錄頁面時,出現了Sql注入的問題。 我有以下代碼:如何防止SQL注入在休眠?
@Component
@Transactional(propagation = Propagation.SUPPORTS)
public class LoginInfoDAOImpl implements LoginInfoDAO{
@Autowired
private SessionFactory sessionFactory;
@Override
public LoginInfo getLoginInfo(String userName,String password){
List<LoginInfo> loginList = sessionFactory.getCurrentSession().createQuery("from LoginInfo where userName='"+userName+"' and password='"+password+"'").list();
if(loginList!=null)
return loginList.get(0);
else return null;
}
}
我將如何防止在這種情況下SQL注入的創建LOGININFO表的表語法如下:?
create table login_info
(user_name varchar(16) not null primary key,
pass_word varchar(16) not null);
請參考此鏈接[1]:http://stackoverflow.com/questions/4606505/prevention-against-sql-injection-in-hibernate –