zoukankan      html  css  js  c++  java
  • spring配置c3p0连接池

    一、spring配置c3p0连接池

    1、导入spring、c3p0的jar包以及MySQL驱动

    2、将链接池所用的属性抽象到db.properties文件中

    jdbc.user=root
    jdbc.password=root
    jdbc.driverClass=com.mysql.jdbc.Driver
    jdbc.jdbcUrl=jdbc:mysql:///spring
    
    jdbc.initPoolSize=5
    jdbc.maxPoolSize=10
    
    

    3、在spring配置文件中配置连接池

        <!-- 导入资源文件-->
        <context:property-placeholder location="classpath:db.properties"></context:property-placeholder>
        <!--配置c3p0数据源-->
        <bean id="dataSource"
              class="com.mchange.v2.c3p0.ComboPooledDataSource">
            <property name="user" value="${jdbc.user}"></property>
            <property name="password" value="${jdbc.password}"></property>
            <property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>
            <property name="driverClass" value="${jdbc.driverClass}"></property>
    
            <property name="initialPoolSize" value="${jdbc.initPoolSize}"></property>
            <property name="maxPoolSize" value="${jdbc.maxPoolSize}"></property>
        </bean>
    
    

    4、测试

        @Test
        public void testDataSource() throws SQLException {
           DataSource dataSource =ctx.getBean(DataSource.class);
            System.out.println(dataSource.getConnection());
        }
    
  • 相关阅读:
    nginx之proxy、cache、upstream模块学习
    lvs负载均衡
    nginx之rewrite匹配需求
    nginx之配置proxy_set_header
    nginx结合fastcgi
    转载:vsftp中的local_umask和anon_umask
    python3.6连接mysql或者mariadb
    在linux环境下安装python3.6
    元字符匹配
    sendEmail
  • 原文地址:https://www.cnblogs.com/shaoyu/p/11671570.html
Copyright © 2011-2022 走看看