一列 多列 查询 基于hibernate
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);
}
}
}
posted on 2015-11-12 17:51 kebizhanmushi 阅读(271) 评论(0) 收藏 举报
浙公网安备 33010602011771号