Topic: Hibernate查询语法求助

  Print this page

1.Hibernate查询语法求助 Copy to clipboard
Posted by: c00lzhang
Posted on: 2005-12-07 18:46

我这样写的语句对吗?封装过的:
public List findGasTypes(String code,String name,String orderBy,String sortType)
{
Object[] values = new Object[2];
values[0] = code;
values[1] = name;
        
return this.getHibernateTemplate().find("select * from GasType where code like ?,name like ?,order by orderBy asc,sortType asc",values);

2.Re:Hibernate查询语法求助 [Re: c00lzhang] Copy to clipboard
Posted by: c00lzhang
Posted on: 2005-12-07 18:49

Post is deleted

3.Re:Hibernate查询语法求助 [Re: c00lzhang] Copy to clipboard
Posted by: bluepure
Posted on: 2005-12-08 09:37

十分怀疑你拼sql字符串的能力Sad

改成下面的样子:

return this.getHibernateTemplate().find("select * from GasType where code like ? and name like ? order by "+orderBy+" asc,"+sortType+" asc",values);

4.Re:Hibernate查询语法求助 [Re: c00lzhang] Copy to clipboard
Posted by: c00lzhang
Posted on: 2005-12-08 10:17

呵呵 谢谢大哥啊 新人一个哈

5.Re:Hibernate查询语法求助 [Re: c00lzhang] Copy to clipboard
Posted by: c00lzhang
Posted on: 2005-12-08 10:32

可是还是不行 555555555555 我太笨了!Sad

6.Re:Hibernate查询语法求助 [Re: bluepure] Copy to clipboard
Posted by: bluepure
Posted on: 2005-12-08 11:44

再改

不好意思刚才我粗心了,没改对:
试一下下面这个:

return this.getHibernateTemplate().find("from GasType where code like ? and name like ? order by "+orderBy+" asc,"+sortType+" asc",values);

7.Re:Hibernate查询语法求助 [Re: c00lzhang] Copy to clipboard
Posted by: c00lzhang
Posted on: 2005-12-08 13:46

还是不行 有错误 好象是说多了,和asc???

8.Re:Hibernate查询语法求助 [Re: c00lzhang] Copy to clipboard
Posted by: c00lzhang
Posted on: 2005-12-08 13:49

写成这样的话就没报错了 但是读不到数据库里的数据出来
public List findGasTypes(String code,String name,String orderBy,String sortType)
{
Object[] values = new Object[2];
        values[0] = code;
        values[1] = name;
        String hql = "from GasType where code like ? and name like ? order by "+orderBy+" "+sortType+"asc";

return this.getHibernateTemplate().find(hql,values);
哎~~~~~~~~~~~苦恼啊!!!

9.Re:Hibernate查询语法求助 [Re: c00lzhang] Copy to clipboard
Posted by: why
Posted on: 2005-12-08 18:02

c00lzhang wrote:
写成这样的话就没报错了 但是读不到数据库里的数据出来
public List findGasTypes(String code,String name,String orderBy,String sortType)
{
Object[] values = new Object[2];
        values[0] = code;
        values[1] = name;
        String hql = "from GasType where code like ? and name like ? order by "+orderBy+" "+sortType+"asc";

return this.getHibernateTemplate().find(hql,values);

How do you call this method?
i.e. what are the values of orderBy and sortType?

10.Re:Hibernate查询语法求助 [Re: c00lzhang] Copy to clipboard
Posted by: bill1
Posted on: 2005-12-12 15:11

写的东西,我真的不太愿意看。


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923