兼容各个数据库的sql语句 Criteria
2011-08-12 20:33
190 查看
Session session = HibernateUtil.getSessionFactory().openSession();
Criteria criteria = session.createCriteria(People.class);
//List list = criteria.list(); //select * from people
//criteria.add(Restrictions.gt("id",2)); //select * from people where id > 2;
//criteria.add(Restrictions.between("id", 1, 5)); //select * from people where id between 1 and 5;
//criteria.add(Restrictions.isNull("password")); //select * from people where password is noll;
//criteria.add(Restrictions.eq("name", "cf")); //select * from people where name = 'cf' ;
//criteria.add(Restrictions.like("name", "_f")); //select * from people where name like '_f';
//criteria.add(Restrictions.lt("id", 6)); //select * from people where id < 6;
//criteria.add(Restrictions.and(Restrictions.ge("id", 2), Restrictions.le("id", 3)));
//select * from people where id>=2 and id<=3;
//criteria.add(Restrictions.or(Restrictions.eq("name", "cf"), Restrictions.gt("id",2)));
//select * from people where id>2 or name='cf';
//criteria.add(Restrictions.in("id", new Integer[]{1,2,3}));
//select * from people where id in (1,2,3);
//criteria.addOrder(Order.asc("name"));
//select * from people order by name asc;
//criteria.setFirstResult(1);
//criteria.setMaxResults(2);
//select * from people limit 1,2;
//criteria.setProjection(Projections.count("id"));
//select count(id) from people ;
//criteria.setProjection(Projections.avg("id"));
//select avg(id) from people;
//criteria.setProjection(Projections.groupProperty("name"));
//select name from people group by name;
//criteria.setProjection(Projections.rowCount());
//select count(*) from people ;
//ProjectionList projectionList = Projections.projectionList();
//projectionList.add(Projections.groupProperty("name"));
//projectionList.add(Projections.rowCount());
//criteria.setProjection(projectionList);
//select name ,count(*) from people group by name;
List list = criteria.list();
Criteria criteria = session.createCriteria(People.class);
//List list = criteria.list(); //select * from people
//criteria.add(Restrictions.gt("id",2)); //select * from people where id > 2;
//criteria.add(Restrictions.between("id", 1, 5)); //select * from people where id between 1 and 5;
//criteria.add(Restrictions.isNull("password")); //select * from people where password is noll;
//criteria.add(Restrictions.eq("name", "cf")); //select * from people where name = 'cf' ;
//criteria.add(Restrictions.like("name", "_f")); //select * from people where name like '_f';
//criteria.add(Restrictions.lt("id", 6)); //select * from people where id < 6;
//criteria.add(Restrictions.and(Restrictions.ge("id", 2), Restrictions.le("id", 3)));
//select * from people where id>=2 and id<=3;
//criteria.add(Restrictions.or(Restrictions.eq("name", "cf"), Restrictions.gt("id",2)));
//select * from people where id>2 or name='cf';
//criteria.add(Restrictions.in("id", new Integer[]{1,2,3}));
//select * from people where id in (1,2,3);
//criteria.addOrder(Order.asc("name"));
//select * from people order by name asc;
//criteria.setFirstResult(1);
//criteria.setMaxResults(2);
//select * from people limit 1,2;
//criteria.setProjection(Projections.count("id"));
//select count(id) from people ;
//criteria.setProjection(Projections.avg("id"));
//select avg(id) from people;
//criteria.setProjection(Projections.groupProperty("name"));
//select name from people group by name;
//criteria.setProjection(Projections.rowCount());
//select count(*) from people ;
//ProjectionList projectionList = Projections.projectionList();
//projectionList.add(Projections.groupProperty("name"));
//projectionList.add(Projections.rowCount());
//criteria.setProjection(projectionList);
//select name ,count(*) from people group by name;
List list = criteria.list();
相关文章推荐
- 利用正则表达式类解析SQL语句,达到Worklist兼容各个RIS数据库的目的
- 利用正则表达式类解析SQL语句,达到Worklist兼容各个RIS数据库的目的
- 利用正则表达式类解析SQL语句,达到Worklist兼容各个RIS数据库的目的
- 通过T-SQL语句实现数据库备份与还原的代码
- mysql 之 sql 语句 之 数据库的表使用
- 各种数据库分页查询sql语句大全
- 数据库表备份SQL语句
- sql语句查询到整个数据库的容量
- SQL常用语句,含查看数据库日志
- 一条SQL语句查询数据库中的所有表、存储过程、触发器 (sysobjects表信息)
- T-SQL语句还原数据库
- mysql 数据库Event定时任务使用详解(Navicat 及直接SQL语句创建)
- sql server中利用sql语句如何创建角色和用户&数据库安全设置 给出了实例
- [数据库] SQL查询语句表行列转换及一行数据转换成两列
- 二、数据库基本SQL语句之表管理
- SQL高级语句-DROP 语句,可以轻松地删除索引、表和数据库。
- sql第二课用transcat_sql来创建数据库的语句
- SQL语句获取所有数据库名、表名、字段名、表字段长度
- 数据库菜鸟不可不看 简单SQL语句小结
- sql语句没问题,在数据库运行ok ,也查出了数据,但就是显示的时候报空指针异常..