比如一个简单的功能,比如设置一个数据为1和0,反复设置点击功能按钮,或者一个列表,上一页下一页反复频繁点击,大概30秒之内,就能导致项目出错并停止运行。出错提示如下。2009-07-31 08:19:44,109 WARN [org.hibernate.jdbc.ConnectionManager] - finalizing with closed connection
2009-07-31 08:19:46,140 WARN [org.hibernate.jdbc.ConnectionManager] - unclosed connection, forgot to call close() on your session?
2009-07-31 08:19:46,156 WARN [org.hibernate.jdbc.ConnectionManager] - finalizing with closed connection
2009-07-31 08:19:46,156 WARN [org.hibernate.jdbc.ConnectionManager] - unclosed connection, forgot to call close() on your session?
2009-07-31 08:19:46,156 WARN [org.hibernate.jdbc.ConnectionManager] - finalizing with closed connection
2009-07-31 08:19:48,937 WARN [org.hibernate.jdbc.ConnectionManager] - unclosed connection, forgot to call close() on your session?
2009-07-31 08:19:48,953 WARN [org.hibernate.jdbc.ConnectionManager] - unclosed connection, forgot to call close() on your session?
2009-07-31 08:19:48,968 WARN [org.hibernate.jdbc.ConnectionManager] - unclosed connection, forgot to call close() on your session?
2009-07-31 08:19:48,968 WARN [org.hibernate.jdbc.ConnectionManager] - finalizing with closed connection
2009-07-31 08:19:53,984 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 0, SQLState: null
2009-07-31 08:19:53,984 ERROR [org.hibernate.util.JDBCExceptionReporter] - Cannot get a connection, pool exhausted
2009-07-31 08:19:53,984 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 0, SQLState: null
2009-07-31 08:19:53,984 ERROR [org.hibernate.util.JDBCExceptionReporter] - Cannot get a connection, pool exhausted
2009-07-31 08:19:53,984 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 0, SQLState: null
2009-07-31 08:19:53,984 ERROR [org.hibernate.util.JDBCExceptionReporter] - Cannot get a connection, pool exhausted
2009-07-31 08:19:53,984 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 0, SQLState: null
2009-07-31 08:19:53,984 ERROR [org.hibernate.util.JDBCExceptionReporter] - Cannot get a connection, pool exhausted
2009-07-31 08:19:53,984 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 0, SQLState: null
2009-07-31 08:19:53,984 ERROR [org.hibernate.util.JDBCExceptionReporter] - Cannot get a connection, pool exhausted
2009-07-31 08:19:53,984 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 0, SQLState: null
2009-07-31 08:19:53,984 ERROR [org.hibernate.util.JDBCExceptionReporter] - Cannot get a connection, pool exhausted
org.hibernate.exception.GenericJDBCException: Cannot open connection
at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:301)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:110)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:88)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1162)
at org.hibernate.loader.Loader.doQuery(Loader.java:390)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
请大家帮我看看,此类问题怎么解决?
代码已经按照标准来制作,正常使用下不会出错。何解?提供一个解决方法。谢谢。

解决方案 »

  1.   

    这个异常是底层打开数据库连接错误,检查SQLServer是否正常服务(端口等)     URL是否应该是:database=数据库名
    <property   name="hibernate.connection.username">   
      sa   
      </property>   
        
      所有的property元素都不要换行   试一下   
        
      <property   name="hibernate.connection.username">sa</property> 
      

  2.   

    使用的是mysql数据库,底层数据肯定没问题的,因为正常使用,只要不是频繁操作,就没问题。
      

  3.   

    是sql数据库吗?如果是,你看看你的认证模式,感觉是你的SQL   server   2000认证模式的问题,你选用混和模式,而不采用NT认证模式,看看有没有用
      

  4.   

    <bean id="dataSource"
    class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName">
    <value>java:comp/env/jdbc/ssh_test</value>
    </property>
    </bean>


    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
    <ref bean="dataSource" />
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">
    org.hibernate.dialect.MySQLDialect
    </prop>

    <prop key="hibernate.connection.autocommit">true</prop> <prop key="hibernate.show_sql">false</prop>
    </props>
    </property> <property name="mappingResources">
    <list>
    <value>com/wj/vo/Article.hbm.xml</value>
    </property>
    </bean>数据连接部分,只要正常操作肯定没问题。
      

  5.   

    Cannot get a connection, pool exhausted连接没有返回到连接池,导致连接池内无可用连接,
    你有操作没有关闭session
      

  6.   

     finalizing with closed connection --关闭连接
    unclosed connection, forgot to call close() on your session? --未关闭连接或连接未正常关闭
    Cannot get a connection, pool exhausted --麽有连接可用喽~一直重复关闭连接 但是却没有调用close方法 导致连接池内的连接已满 已经不能在建立新的连接 。检查 获得conn和关闭conn那块 看是不是有什么不妥的地方在频繁操作的时候 不会释放资源呢
      

  7.   

    request.setAttribute("currentPage", currentPage);
    request.setAttribute("lineSize", lineSize);
    request.setAttribute("allRecorders", allRecorders);
    request.setAttribute("all", all);

    request.setAttribute("flagname", "mode");
    request.setAttribute("flagvalue", mode);

    request.setAttribute("jspUrl", "article.do");
    request.setAttribute("action", "list");列表部分也就利用到这些参数传递,应该没有使用session的。是不是列表的list.jsp页面,需要在最后一行关闭数据连接?若是的话,请问怎么做才合适?
      

  8.   

    楼主怎么不用SPRING的数据源呢?
      

  9.   

    楼主不知道hibernate也有Session吗?你的数据库操作的代码是怎样的?没有利用spring的hibernateTemplate吧,估计是你自己通过hibernate的方式获取了session而没有关闭,把代码贴出来
      

  10.   

    没有关闭session,楼主最好把代码贴出来看看
      

  11.   

    public void delete(int id) throws Exception {
    String hql = "DELETE FROM Hd WHERE id=?";
    Query q = super.getSession().createQuery(hql);
    q.setInteger(0, id);
    q.executeUpdate();

    } public void insert(Hd hd) throws Exception {
    super.getSession().save(hd);

    }代码如上,怎么在其中关闭session,怎么写?
      

  12.   

    super.getSession().close();是不是每个功能内添加上面这个语句?public void delete(int id) throws Exception { 
    String hql = "DELETE FROM Hd WHERE id=?"; 
    Query q = super.getSession().createQuery(hql); 
    q.setInteger(0, id); 
    q.executeUpdate(); 
    super.getSession().close();
      

  13.   

    需要调用 connection.close();最保险的做法是在finally块中关闭连接,这样保证任何情况下都能关闭连接,释放连接资源
    try{   } catch() finally{connection.close(); }
      

  14.   

    是你的方法里面的session没有关闭,在方法最后加getSession.close(), 每次调用之前flush(),应该就没问题了。
      

  15.   

    连接没有正常关闭,调用session的close()方法

        <bean id="dataSource" 
         class="org.springframework.jndi.JndiObjectFactoryBean"> 加destroy-method="close"
          <property name="jndiName"> 
              <value>java:comp/env/jdbc/ssh_test </value> 
          </property> 
        </bean> 
      

  16.   

    try it! to prevent someone from submitting repeatlyif (!isTokenValid(request, true)) //设置reset参数为true,表示在判断后删除令牌,也可通过resetToken方法删除
                {
                    saveToken(request); //重新获得令牌
                    throw new BossGlobalException("common.error.duplicatesubmit",
                        null);
                }
      

  17.   

    没关闭session,数据库连接占满,获取不到连接!
      

  18.   

    应该是session没有关闭 
    建议在获取数据库连接,创建session的方法之前 
    加个if判断语句,来判断一下session是否关闭 
    要是没有先关闭再建立新的session 
      

  19.   

    连接没有关闭  建议使用spring的数据库操作