//HQL的简单查询
public void test(){
Session session = HibernateUtils.getCurrentSession();
Transaction transaction = session.beginTransaction();
Query query = session.createQuery("from Customer");
List list = query.list();
for (Customer customer : list) {
System.out.println(customer);
}
transaction.commit();
}
//HQL的简单查询之别名查询
public void test(){
Session session = HibernateUtils.getCurrentSession();
Transaction transaction = session.beginTransaction();
//c是别名,但HQL不支持*,聚合函数中的*除外
Query query = session.createQuery("select c from Customer c");
List list = query.list();
for (Customer customer : list) {
System.out.println(customer);
}
transaction.commit();
}
排序查询:
//HQL的排序查询
public void test3(){
Session session = HibernateUtils.getCurrentSession();
Transaction transaction = session.beginTransaction();
//默认
// Query query = session.createQuery(" from Customer order by cust_id");
//降序
Query query = session.createQuery(" from Customer order by cust_id desc");
//升序
// Query query = session.createQuery(" from Customer order by cust_id asc");
List list = query.list();
for (Customer customer : list) {
System.out.println(customer);
}
transaction.commit();
}
条件查询:
public void test3(){
Session session = HibernateUtils.getCurrentSession();
Transaction transaction = session.beginTransaction();
//条件查询
//1.按位置绑定,多个条件时类推
// Query query = session.createQuery("from Customer where cust_id=?");
// query.setParameter(0, 1l);
// List list = query.list();
//2.按名称绑定--根据参数位置进行绑定
//aaa,bbb这些名字随便起,但与:之间不能有空格
Query query = session.createQuery("from Customer where cust_id = :aaa and cust_name = :bbb");
//设置参数
query.setParameter("aaa", 1l);
query.setParameter("bbb", "22");
List list = query.list();
transaction.commit();
}
投影查询:
public void test3(){
Session session = HibernateUtils.getCurrentSession();
Transaction transaction = session.beginTransaction();
//单个属性
// List
分页查询:
//HQL的分页查询
public void test3(){
Session session = HibernateUtils.getCurrentSession();
Transaction transaction = session.beginTransaction();
Query query = session.createQuery("from Customer");
query.setFirstResult(0);
query.setMaxResults(2);
List list = query.list();
for (Object object : list) {
System.out.println(object);
}
transaction.commit();
}
分组统计查询:
//HQL的分组统计查询
public void test3(){
Session session = HibernateUtils.getCurrentSession();
Transaction transaction = session.beginTransaction();
//聚合函数:count(),sum(),max(),min(),avg()
// Object object = session.createQuery("select count(*) from Customer").uniqueResult();
// System.out.println(object);
Query query = session.createQuery("select cust_id,count(*) from Customer group by cust_name");
List object = query.list();
for (Object[] object2 : object) {
System.out.println(Arrays.toString(object2));
}
transaction.commit();
}
QBC:
Query By Criteria,条件查询。是一种更加面向对象化的查询的方式。
简单查询:
//简单查询
public void test(){
Session session = HibernateUtils.getCurrentSession();
Transaction transaction = session.beginTransaction();
//获得Criteria对象
Criteria criteria = session.createCriteria(Customer.class);
List list = criteria.list();
for (Customer customer : list) {
System.out.println(customer.toString());
}
transaction.commit();
}
排序查询:
//排序查询
public void test1(){
Session session = HibernateUtils.getCurrentSession();
Transaction transaction = session.beginTransaction();
//获得Criteria对象
Criteria criteria = session.createCriteria(Customer.class);
//升序查询,对应降序为desc
criteria.addOrder(Order.asc("cust_id"));
List list = criteria.list();
for (Customer customer : list) {
System.out.println(customer.toString());
}
transaction.commit();
}
分页查询:
//分页查询
public void test1(){
Session session = HibernateUtils.getCurrentSession();
Transaction transaction = session.beginTransaction();
//获得Criteria对象
Criteria criteria = session.createCriteria(Customer.class);
criteria.setFirstResult(0);
criteria.setMaxResults(2);
List list = criteria.list();
for (Customer customer : list) {
System.out.println(customer);
}
transaction.commit();
}
条件查询:
//条件查询
public void test1(){
Session session = HibernateUtils.getCurrentSession();
Transaction transaction = session.beginTransaction();
//获得Criteria对象
Criteria criteria = session.createCriteria(Customer.class);
/**
* = eq
* > gt
* >= ge
* < lt
* <= le
* <> ne 不等于
*/
//设置条件
criteria.add(Restrictions.eq("cust_name", "11"));
List list = criteria.list();
for (Customer customer : list) {
System.out.println(customer);
}
transaction.commit();
}
统计查询:
//统计查询
@Test
public void test1(){
Session session = HibernateUtils.getCurrentSession();
Transaction transaction = session.beginTransaction();
//获得Criteria对象
Criteria criteria = session.createCriteria(Customer.class);
/**
* add :普通的条件,where后面事件
* addOrder:排序
* setProjection:聚合函数和group by having
*/
criteria.setProjection(Projections.rowCount());
Long num = (Long)criteria.uniqueResult();
System.out.println(num);
transaction.commit();
}
离线查询:
//离线查询
public void test1(){
DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Customer.class);
detachedCriteria.add(Restrictions.ilike("cust_name", "1%"));
Session session = HibernateUtils.getCurrentSession();
Transaction transaction = session.beginTransaction();
Criteria criteria = detachedCriteria.getExecutableCriteria(session);
List list = criteria.list();
for (Customer customer : list) {
System.out.println(customer);
}
}
多表查询:
//多表查询
public void test1(){
Session session = HibernateUtils.getCurrentSession();
Transaction transaction = session.beginTransaction();
//SQL:SELECT * FROM cst_customer c INNER JOIN cst_linkman l ON c.cust_id = l.lkm_cust_id;
//HQL(内连接):from Customer c inner join c.linkMans
//List list = session.createQuery("from Customer c inner join c.linkMans").list();
//HQL(迫切内连接):在普通内连接inner join后添加一个关键字fetch。它发的SQL语句与
//内连接一样,作用:通知hibernate将数据封装到对象里,因为Customer中有LinkMan的集合,所以把
//LinkMan封装到Customer中,返回的list集合中放的是Customer(select distincr c 是为了去掉重复)
List list = session.createQuery("select distinct c from Customer c inner join fetch c.linkMans").list();
}
SQL:
public void test1(){
Session session = HibernateUtils.getCurrentSession();
Transaction transaction = session.beginTransaction();
SQLQuery sqlQuery = session.createSQLQuery("select * from cst_customer");
sqlQuery.addEntity(Customer.class);
List list = sqlQuery.list();
for (Customer customer : list) {
System.out.println(customer);
}
transaction.commit();
}
--只包含执行部分的PL/SQL块
--set serveroutput off
begin
dbms_output.put_line('Hello,everyone!');
end;
select * from emp;
--包含定义部分和执行部分的PL/SQL块
declare
v_ename varchar2(5);
begin
select
转:http://stackoverflow.com/questions/6352208/how-to-solve-plugin-execution-not-covered-by-lifecycle-configuration-for-sprin
maven报错:
Plugin execution not covered by lifecycle configuration:
要使用MonkeyRunner,就要学习使用Python,哎
先抄一段官方doc里的代码
作用是启动一个程序(应该是启动程序默认的Activity),然后按MENU键,并截屏
# Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRun