`
xxtianxiaxing
  • 浏览: 705270 次
  • 性别: Icon_minigender_1
  • 来自: 陕西
社区版块
存档分类
最新评论

Java 异常:Cannot create PoolableConnectionFactory (Too many connections)

阅读更多
JDBCExceptionReporter:77 SQL Error: 0, SQLState: null
JDBCExceptionReporter:78 Cannot create PoolableConnectionFactory (Too many connections)
SettingsFactory:117 Could not obtain connection metadata
org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Too many connections)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1225)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:82)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:84)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:814)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:732)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:140)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:94)
at com.hereim.util.spring.BeanHelp.getBean(BeanHelp.java:28)
at com.hereim.server.LoginLogoutService.parseLogin(LoginLogoutService.java:104)
at com.hereim.server.LoginLogoutService.parseXML(LoginLogoutService.java:66)
at com.hereim.server.IMServer$ThreadForSocket.HandleReceivePacket(IMServer.java:86)
at com.hereim.server.IMServer$ThreadForSocket.run(IMServer.java:60)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException: Too many connections
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:980)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:910)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3923)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1273)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2031)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:718)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:298)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:294)
at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1247)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1221)
... 32 more
JDBCExceptionReporter:77 SQL Error: 0, SQLState: null
JDBCExceptionReporter:78 Cannot create PoolableConnectionFactory (Too many connections)
JDBCExceptionReporter:77 SQL Error: 0, SQLState: null
JDBCExceptionReporter:78 Cannot create PoolableConnectionFactory (Too many connections)
org.hibernate.exception.GenericJDBCException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
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:426)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:119)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1326)
at com.hereim.util.spring.BaseDAO.queryBySql(BaseDAO.java:1491)
at com.hereim.dao.IMUserDAOImpl.login(IMUserDAOImpl.java:24)
at com.hereim.api.IMUserImpl.login(IMUserImpl.java:20)
at com.hereim.server.LoginLogoutService.parseLogin(LoginLogoutService.java:105)
at com.hereim.server.LoginLogoutService.parseXML(LoginLogoutService.java:66)
at com.hereim.server.IMServer$ThreadForSocket.HandleReceivePacket(IMServer.java:86)
at com.hereim.server.IMServer$ThreadForSocket.run(IMServer.java:60)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Too many connections)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1225)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:82)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:423)
... 14 more
Caused by: com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException: Too many connections
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:980)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:910)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3923)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1273)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2031)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:718)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:298)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:294)
at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1247)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1221)
... 17 more



session 关闭
protected void closeSession(Session session) {  
 
        if (session != null && session.isOpen())  
              
            session.close();  
          
        session = null;  
          
    }  


spring配置文件:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">   
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>   
<property name="url" value="jdbc:mysql://192.168.0.3:3306/HereOnLineIM"></property>   
<property name="username" value="hereim"></property>   
<property name="password" value="hereim"></property>   
<property name="maxActive" value="100"></property>  
<property name="maxIdle" value="30"></property>  
<property name="maxWait" value="1000"></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.current_session_context_class">thread</prop>
            </props>
        </property>
       
        <property name="mappingResources">
            <list>
            <value>com/hereim/dao/imUser.hbm.xml</value>
                <value>com/hereim/dao/Imgroup.hbm.xml</value>
                <value>com/hereim/dao/Imcontact.hbm.xml</value>
                <value>com/hereim/dao/HereOnLineUser.hbm.xml</value>
                <value>com/hereim/dao/HelpImonline.hbm.xml</value>
            </list>
        </property>
    </bean>
   





   问题已解决,关闭session的 问题this.getHibernateTemplate().getSessionFactory().close();
protected void closeSession(Session session) {  
 
        if (session != null && session.isOpen())  
              
            session.close();  
            this.getHibernateTemplate().getSessionFactory().close();
        session = null;  
          
    }  



2
0
分享到:
评论

相关推荐

    sql server 2005设置sql身份验证 Cannot create PoolableConnectionFactory (用户 'sa' 登录失败。该

    在SQL Server 2005中,"Cannot create PoolableConnectionFactory (用户 'sa' 登录失败。该用户与可信 SQL Server 连接无)" 错误通常表明在尝试使用SQL Server的身份验证方式登录时遇到了问题。这篇博客文章可能详细...

    用户 'sa' 登录失败。该用户与可信 SQL Server 连接无关联

    用户 'sa' 登录失败。该用户与可信 SQL Server 连接无关联

    学习有关连接池的使用

    在Java开发中,连接池是一种优化数据库访问性能的重要技术,它可以高效地管理和重用数据库连接,从而避免频繁创建和销毁连接带来的性能开销。本文将深入讲解如何在Java环境中,特别是Tomcat服务器中配置和使用连接池...

    WEB-INF中的web.xml中之前增加以下配置:

    确认SQL Server 2000可以远程连接,除了开放1433端口外,还要升级数据库到SP3或SP4,否则连接会发出SQLNestedException:Cannot create PoolableConnectionFactory ([Microsoft][SQLServer 2000 Driver for JDBC]...

    kettle常见问题

    kettle常见问题kettle常见问题kettle常见问题kettle常见问题kettle常见问题

    Jmeter连接Mysql数据库实现过程详解

    在执行JDBC Request之后,我们可能会出现一个报错:java.sql.SQLException: Cannot create PoolableConnectionFactory (The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more...

    Jmeter JDBC请求常见问题解决方案

    该问题的错误信息为:Cannot create PoolableConnectionFactory (The server time zone value '???��������??��??' is unrecognized or represents more than one time zone. You must configure either ...

    关于JDBC连接池的java类

    Java JDBC连接池是一种高效管理数据库连接的技术,它允许应用程序重复使用已经建立的数据库连接,而不是每次需要时都创建新的连接。这显著提高了性能并减少了系统资源的消耗,尤其是在高并发的环境中。本类库提供了...

    数据库连接包

    DBCP作为Java应用中的一个关键组件,它提高了数据库操作的性能和效率。数据库连接池是一种管理数据库连接的机制,通过预先创建并维护一定数量的数据库连接,应用程序可以快速地获取和释放连接,避免了频繁地创建和...

    c3p0所需jar包

    C3P0是一款开源的Java连接池,全称为ComMChange V2 C3P0,由M. J. Franklin创建并维护。它提供了一种高效、灵活且强大的数据库连接管理方式,广泛应用于Java应用程序中,特别是对于那些需要大量并发数据库访问的Web...

    thriftpool:Thrift RPC连接池,java实现,基于apache commons pool

    在Java中,对象的创建和销毁是有成本的,尤其是在高并发环境下,频繁创建和销毁对象会导致大量的内存分配和回收,影响系统性能。通过使用对象池,可以预先创建一定数量的对象,供多个请求共享,减少对象的创建和销毁...

    commons-dbcp-1.2.2 JAR包和API

    6. **异常处理**:DBCP提供了一套完善的异常处理机制,包括`PoolManagers`、`Poolables`等,帮助开发者更好地处理和理解在连接池操作过程中可能出现的问题。 在使用`commons-dbcp-1.2.2`时,开发者需要注意以下几点...

    java常用工具类之数据库连接类(可以连接多种数据库)

    Java中的数据库连接是应用程序与数据库交互的基础,而`DBUtil`类是一个常见的工具类,用于封装数据库连接的创建、管理以及执行SQL语句的过程。在Java中,我们通常使用JDBC(Java Database Connectivity)API来实现...

    RabbitMQ客户端连接池实现代码可直接复制项目中使用

    在Java开发中,我们常常需要管理与RabbitMQ服务器的连接,以优化资源使用和提高性能。连接池就是解决这一问题的有效手段。 本项目提供的"RabbitMQ客户端连接池实现代码"旨在帮助开发者快速在自己的Java项目中集成...

    c3p0连接池与源码

    2. **异常处理**: 在获取和使用连接时,应妥善处理异常,确保资源正确释放。 3. **及时升级**: 关注c3p0的更新和安全修复,保持库版本的最新。 6. **性能优化**: 结合JMX监控,持续优化连接池配置,提高应用性能。...

    dbcp 1.2.2

    Apache Commons DBCP 1.2.2 是一个在Java应用程序中管理数据库连接池的开源库。这个版本的DBCP是Apache Commons项目的一部分,旨在提供一个健壮、高性能的数据库连接池实现,以提高Java应用的数据库访问效率。在本篇...

    commons-dbcp-1.4源码

    3. **异常处理**:了解DBCP如何处理连接失败、超时和废弃连接等问题。 4. **性能优化**:研究如何通过调整连接池参数来提高性能,例如设置合适的连接最大值、最小值和超时时间。 5. **线程安全**:DBCP作为多线程...

    数据库连接池.pdf

    - **创建PoolableConnectionFactory**:这是DBCP的核心,它将普通数据库连接转换为池化的连接,可以被对象池管理和回收。 - **注册PoolingDriver**:`PoolingDriver`是DBCP提供的JDBC驱动,它允许通过特定的URL...

    commons-dbcp.jar,commons-poor.rar

    Commons-DBCP与Commons-Pool是Apache软件基金会下的两个重要的Java库,它们在Java数据库连接(JDBC)处理和对象池管理方面扮演着关键角色。让我们深入了解一下这两个组件。 **Commons-DBCP** Commons-DBCP,全称为...

    连接不到数据库【转】整理.pdf

    错误的配置可能导致`PoolableConnectionFactory`无法创建,从而抛出`SQLNestedException`。检查`server.xml`文件中的DataSource配置,确保用户名、密码、URL等参数正确无误。 5. **网络问题**:除了上述软件配置,...

Global site tag (gtag.js) - Google Analytics