Hibernate c3p0的整合

Hibernate整合c3p0

  Hibernate中可以使用默认jdbc连接池,但是无论功能还是性能都不如c3p0

  在pom添加jar包:

        <!-- hibernate-c3p0 -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-c3p0</artifactId>
            <version>5.2.10.Final</version>
        </dependency>

   在hibernate.cfg.xml中配置:

        <!-- 整合c3p0 -->
        <property name="hibernate.connection.provider_class">
      org.hibernate.c3p0.internal.C3P0ConnectionProvider
     </property> <property name="c3p0.min_size">10</property> <property name="c3p0.max_size">20</property>

   测试:

        Session session = HibernateUtil.openSession();
        session.doWork(new Work() {

            public void execute(Connection connection) throws SQLException {
                 System.out.println(connection);
            }
            
        });
        session.close(); 

   Console:

com.mchange.v2.c3p0.impl.NewProxyConnection@1b1637e1 [wrapping: com.mysql.jdbc.JDBC4Connection@18151a14]
原文地址:https://www.cnblogs.com/roxy/p/7640529.html