public class AdminAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
// TODO Auto-generated method stub
String userName=request.getParameter("userName");
String userPwd=request.getParameter("userPwd"); String uPwd=null;
Session session=SessionFactory.currentSession();
Transaction tx=session.beginTransaction();
Query query=session.createQuery("select * from myhibernate where username='"+ userName +"'");
try{
Iterator it=query.iterate(); //debug 直接转到 catch(Exception e) 捕获e的信息如下
AdminTable admin=(AdminTable) it.next();
uPwd=admin.getUserPwd();
}catch(Exception e){
return mapping.findForward("error");
}
tx.commit();
SessionFactory.closeSession();
if(uPwd.equals(userPwd)){
return mapping.findForward("show");
}else{
return mapping.findForward("error");
}
}
}
捕获e的信息: net.sf.hibernate.QueryException: unexpected token: as [select * from myhibernate as a where a.username='1']
大家帮帮忙,我是新手,在线等指教
解决方案 »
- com.caucho.hessian.io.HessianServiceException: The service has no method named
- <input type="file" value="浏览..."> 标签下重复上传浏览按钮失效
- hibernate+struts+spring为什么所有的jsp页面都不能正常打开?
- 如何用session 控制页面安全
- 紧急问题:我级联数据表怎么查数据库有问题呢???
- 请问这句什么意思
- TOMCAT配置MYSQL连接池,出现No operations allowed after connection closed
- 请问在oracle中可以象在sql server中设置自增值和设置备注型字段?
- 动态生成的页面背景图案问题?
- 关于INCLUDE得问题!!!
- 请懂得人帮我看看!
- c:foreach异常
Query query=session.createQuery("from AdminTable where username='"+ userName +"'");
其中,粗体部分是你的“myhibernate”表所对应的实体类。
你可能注意到了,没写“select”,是的,就是不需要,嘿嘿。第二个解决方法(使用本地SQL查询):
SQLQuery query=session.createSQLQuery("select * from myhibernate where username='"+ userName +"'");