码迷,mamicode.com
首页 > Web开发 > 详细

一列 多列 查询 基于hibernate

时间:2015-11-12 20:03:14      阅读:308      评论:0      收藏:0      [点我收藏+]

标签:

package com.haha.test;

import java.util.List;

import org.hibernate.Hibernate;
import org.hibernate.Query;
import org.hibernate.Session;

import com.haha.dao.HibernateSessionFactory;

public class Test一列 {


public static void main(String[] args) {
String hql="select b.title from Books b where b.title like ‘java%‘";
Session ss=HibernateSessionFactory.getSession();
Query qq=ss.createQuery(hql);
List<String> list=qq.list();
for(String s:list){
System.out.println(s);
}
}

}

 

 

2

package com.haha.test;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import com.haha.dao.HibernateSessionFactory;

public class Test多列 {

/**
* @param args
*/
public static void main(String[] args) {
String hql=
"select b.title,b.unitprice from Books b where b.title like ‘java%‘";
Session ss=HibernateSessionFactory.getSession();
Query qq=ss.createQuery(hql);
List<Object[]> list=qq.list();
for(Object[] objs:list){
String title=(String) objs[0];
Double price=(Double) objs[1];
System.out.println(title+","+price);
}

}

}

一列 多列 查询 基于hibernate

标签:

原文地址:http://www.cnblogs.com/tian114527375/p/4959784.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!