我用struts2 hibernate连接mysql做了个登录程序,action代码一:
String querySql = "from   Userinfo as cust where"
+ " cust.loginname =" + userinfo.getLoginname()
+ " and cust.password = " + userinfo.getPassword() + "";在登录页面输入 123 and exists (from Userinfo) ;123则sql语句就成了: 
from   Userinfo as cust where cust.loginname =123 and exists (from Userinfo)  and cust.password = 123(hql语句)
就能够登录。
可是代码换成代码二:
String querySql = "from   Userinfo as cust where"
+ " cust.loginname ='" + userinfo.getLoginname()
+ "' and cust.password = "' + userinfo.getPassword() + "'";
在登录页面输入 123 and exists (from Userinfo) ;123则sql语句就成了: 
from   Userinfo as cust where cust.loginname ='123 and exists (from Userinfo)'  and cust.password = '123'(hql语句)
就会提示用户名或者密码不正确。对于代码二该怎么注入?