项目是hibernate搭建的,
功能是页面实时刷新
dao方法每次都 关闭了session
问题来了
但是如果不重启tomcat,oracle中,后台会话里面会一直在增加 求大神指教
附上代码
public List fingAll(){
List list = new ArrayList();
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
Session session = HibernateSessionFactory.getSession();
Transaction tx = session.beginTransaction();
conn = session.connection();
String queryString = "select name,database,sql,unit from kpi_name where isstart = '1' order by to_number(ID)";
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(queryString);
while (rs.next()) {
String tagname = rs.getString("name");
String databasetype = rs.getString("database");
String sql = rs.getString("sql");
String unit = rs.getString("unit");
Name name = new Name(tagname, databasetype, sql, unit);
list.add(name );
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
close(rs, stmt, conn);
if (session != null) {
HibernateSessionFactory.closeSession();
}
}
return list;
}
Session session = HibernateUtil.getSession();
session.beginTransaction();//开启事务
String hql="select name,database,sql,unit from kpi_name where isstart = '1' order by to_number(ID)"; //此处的表明应该换成实体类名哦,相应的列名也要换成对象名,自己改一下
Query query=session.createQuery(hql);//创建Query对象
List<Object[]> list = query.list();//获取结果集,当然你的查询语句结果好像就一条,你可以在上一步查出唯一的一条值
//循环获取想要的对象值
for(Object[] obj:list){
....
}
session.getTransaction().commit();
纯手写,不知道有没有错,呵呵!!!