日期:2014-05-19 浏览次数:20723 次
package com.labmanager.fw.JUNIT;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.labmanager.fw.data.bo.Lab;
import com.labmanager.fw.util.HibernateSessionFactory;
public class PageDeviceTest{
public List getResultCount(String table){
Session session=HibernateSessionFactory.getSession();
Transaction ts=session.beginTransaction();
List list=new ArrayList();
String sql="select count(*) from "+table+" where id > 0";
try{
ts.begin();
SQLQuery sqlQuery=session.createSQLQuery(sql);
list=sqlQuery.list();
ts.commit();
System.out.println("查询到数据"+list.get(0).toString()+"条");
}catch(Exception e){
ts.rollback();
e.printStackTrace();
}finally{
HibernateSessionFactory.closeSession();
}
return list;
}
public void dispaly(){
List list=new ArrayList();
list=this.getResultCount("tblab");
Iterator it=list.iterator();
while(it.hasNext()){
System.out.println(((Lab)it.next()).getName());
}
}
public static void main(String[] args){
new PageDeviceTest().dispaly();
}
}