+ -
当前位置:首页 → 问答吧 → sqlServer2008 Hibernate 查询问题!望高手解惑!

sqlServer2008 Hibernate 查询问题!望高手解惑!

时间:2011-08-21

来源:互联网

这是一个查询方法,总是报:Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: 关键字 'User' 附近有语法错误。

public User findUserByNameAndPsw(String userId, String psw) {
String hql="from User us where us.id=? and us.psw=?";
List<User> us=getHibernateTemplate().find(hql,new String[]{userId,psw});
System.out.println(us.size());
if(us.size()!=0&&us!=null)
{
return us.get(0);
}
else
{
return null;
}
 
}
奇怪的是同样的程序代码我在oracle中能用,为啥我换成sqlServer2008就不行了呢?高手解惑啊!

作者: han3970956   发布时间: 2011-08-21

from User as us where us.id=? and us.psw=?
哥们oracle和sql语法不一样 的

作者: LMAOhuaNL   发布时间: 2011-08-21

引用 1 楼 lmaohuanl 的回复:

from User as us where us.id=? and us.psw=?
哥们oracle和sql语法不一样 的
我用你说的也是报一样的错误啊 ,大哥

作者: han3970956   发布时间: 2011-08-21

String hql="from User us where us.id=:id and us.psw=:psw";
Map<String,String> map=new HashMap<String,String>();
map.put("id",userId);
map.put("pws",pws);
你这样试试看,差不多是这样的,好久没用这种方法了

作者: mmqswan   发布时间: 2011-08-21

热门下载

更多