执行几次查询之后就不能查询了,页面不动了

本文探讨了在使用Hibernate进行数据库操作时出现的“finalizingwithclosedconnection”警告问题,并提供了具体的代码修改方案来确保每次查询结束后正确关闭连接。

每执行依次查询,控制台就有这样的警告 

警告: finalizing with closed connection
2006-9-18 14:38:26 org.hibernate.jdbc.ConnectionManager finalize

修改前

 

public class Employee_sortDAOImpl extends HibernateDaoSupport implements Employee_sortDAO {   
      
   
public int getEmployee_sortCount() throws HibernateException {          
        String querySentence 
= "SELECT count(*) FROM Employee_sort_info";   
        List list 
= this.getHibernateTemplate().find(querySentence);   
        Integer count 
= (Integer) list.get(0);   
        
return count;   
    }
   
    
public List getEmployee_sortByPage(Page page) throws HibernateException {   
        String querySentence 
= "FROM Employee_sort_info";   
        Query query 
= getSession().createQuery(querySentence);   
        query.setFirstResult(page.getBeginIndex()).setMaxResults(page.getEveryPage());   
        
return query.list();   
    }
   
  
}
  

 

修改后

 

public class Employee_sortDAOImpl extends HibernateDaoSupport implements  
        Employee_sortDAO 
{     
    
public int getEmployee_sortCount() throws HibernateException {         
        String querySentence 
= "SELECT count(*) FROM Employee_sort_info";   
        List list 
= this.getHibernateTemplate().find(querySentence);   
        Integer count 
= (Integer) list.get(0);   
        
return count;   
    }
   
    
public List getEmployee_sortByPage(Page page) throws HibernateException {   
        String querySentence 
= "FROM Employee_sort_info";   
        Session session
=this.getHibernateTemplate().getSessionFactory() .openSession();   
        Query query 
= session.createQuery(querySentence);   
        query.setFirstResult(page.getBeginIndex()).setMaxResults(page.getEveryPage());         
        List list 
= query.list();   
        session.close();   
        
return list;   
    }
   
}
   

 

执行几次查询之后就不能查询了,页面不动了,是因为connection没有关闭吗

如果您extends HibernateDaoSupport ,再getSession()是不能自动关闭的?????

能解惑一下吗?各位!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值