论坛首页 入门技术论坛

在登录界面中根据用户名和用户查询该用户是否存在时的问题?

浏览 1771 次
该帖已经被评为新手帖
作者 正文
   发表时间:2008-07-18  

本人在使用Spring + hiberante中来根据用户名和用户密码来取得用户的基本信息,可是当用户名存在时,不是按预期所返回null,而在调用此方法时直接出现异常。

//------根据用户名和用户密码来取得用户的基本信息,如有多条,只取第一条
   
    public Ctlm06 getUserInfo(String usrName,String Password)
    {
    try {
         Ctlm06 ctlm06 =null;
         String queryString = "select ctlm06 from Ctlm06 as ctlm06 where ctlm06.usrName="+usrName+" and ctlm06.usrPwd="+Password;
             List lstResutl=getHibernateTemplate().find(queryString);
              if(lstResutl.size()>0) //表示没有找到此用户信息
                       {
                     ctlm06 = (Ctlm06) lstResutl.get(0);
                         }
          return ctlm06;
    }catch (RuntimeException re) {
                     log.error("save failed", re);
                     throw re;
                    }
    }
//---------------------------------------在另外一个类中调用上方法
Ctlm06 ctlm06 = ctlm06Service.getUserInfo(strUserName, strPassword);
if(ctlm06!=null){ //表示成功登陆
logger.log("用户名为:"+ctlm06.getUsrName()+"成功登陆本系统");
  }但是直接报错;错误如下:
javax.servlet.ServletException: Hibernate operation: could not execute query; bad SQL grammar [select ctlm06x0_.com_id as com1_3_, ctlm06x0_.usr_id as usr2_3_, ctlm06x0_.usr_pwd as usr3_3_, ctlm06x0_.usr_name as usr4_3_, ctlm06x0_.dept_id as dept5_3_, ctlm06x0_.wrkgrp_id as wrkgrp6_3_, ctlm06x0_.shgrp_flag as shgrp7_3_, ctlm06x0_.clerk_id as clerk8_3_ from rsgl.ctlm06 ctlm06x0_ where ctlm06x0_.usr_name=ggg and ctlm06x0_.usr_pwd=ggg]; nested exception is com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 'ggg' in 'where clause'
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:523)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
haodong.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:23)

请各位高手看下,多谢!!!!!!!!!!
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics