注册 登录
编程论坛 J2EE论坛

struts+hibernate 问题。。

zhangjipeng 发布于 2007-12-25 10:54, 1178 次点击
错误:
     javax.servlet.ServletException: could not execute query
 
action文件:
     
    public ActionForward execute (ActionMapping mapping,  
            ActionForm form,
            HttpServletRequest request,
            HttpServletResponse response) {
        IndexForm indexform = new IndexForm();
        Session session = HibernateSessionFactory.getSession();
        String hql="from welcome i where i.name="+request.getParameter("name")+" and i.password="+request.getParameter("password");
        Query query = session.createQuery(hql);
        System.out.println(hql);
        List list = null;
        list = query.list();
        System.out.println(list.size());
        if(list.isEmpty())
            return mapping.findForward("no");
        else
            return mapping.findForward("ok");
    }

奇怪的是我在页面上输入一条数据库里没有的数据他会正确forword到no,如果数据库里有数据他就报could not execute query 错误。请教了。。。。。
4 回复
#2
黄袖标2007-12-25 11:44
from welcome

Welcome
是不是大小写搞错了
这个要个po中定义的一致。
#3
zhangjipeng2007-12-25 11:46
问题已解决。。自己太粗心。!hql格式错误:
 hql="from welcome i where i.name='"+request.getParameter("name")+" 'and i.password='"+request.getParameter("password")"'"; 加上单引号就OK了。。。
#4
黄袖标2007-12-25 12:02
有时候报sql错误,直接把show-sql 设置成true,然后把那条出错的sql放到工具里跑下,比如plsql,这样对于找sql语法错误很快的。
#5
roemin2010-01-24 19:40
welcome这个是实体类的名称  要大写的!
1