• Java C3p0在Spring中运用


    1、导入jar包

    /Spring/lib/mysql-connector-java-5.1.39-bin.jar

    /Spring/lib/c3p0-0.9.1.2.jar
    /Spring/lib/cglib-3.2.2.jar
    /Spring/lib/mchange-commons-java-0.2.12.jar

    2、配置db文件,以mysql为例

    jdbc.url=root
    jdbc.password=niuheng
    jdbc.jdbcUrl=jdbc:mysql://localhost:3306/vShop?useUnicode=true&characterEncoding=UTF-8
    jdbc.driverClass=com.mysql.jdbc.Driver

    3、配置Spring文件

    <!-- 加载配置文件 -->
    <bean id="dbPropertyConfig"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
      <property name="locations">
      <list>
      <value>classpath:db.properties</value>
      </list>
      </property>
    </bean>
    <!-- 配置数据源dataSourse -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
    destroy-method="close">
      <property name="user" value="${jdbc.url}">
    </property>
      <property name="password" value="${jdbc.password}">
    </property>
      <property name="jdbcUrl" value="${jdbc.jdbcUrl}">
    </property>
      <property name="driverClass" value="${jdbc.driverClass}">
    </property>
    <!-- 连接池中保留的最小连接数,默认为:3 -->
      <property name="minPoolSize" value="3" />
    <!-- 连接池中保留的最大连接数。默认值: 15 -->
      <property name="maxPoolSize" value="15" />
    </bean>
    <!-- 配置jdbc template -->
      <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
      <property name="dataSource" ref="dataSource"></property>
    </bean>

  • 相关阅读:
    BZOJ 2574: [Poi1999]Store-Keeper
    BZOJ 1024: [SCOI2009]生日快乐
    BZOJ 2541: [Ctsc2000]冰原探险
    hihoCoder 1303 数论六·模线性方程组
    Codeforces 710 D. Two Arithmetic Progressions
    BZOJ 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘
    ZJOI2014 2048
    51Nod 1766 树上的最远点对
    Codeforces 727 F. Polycarp's problems
    BZOJ 3736: [Pa2013]Karty
  • 原文地址:https://www.cnblogs.com/hylinux/p/6373756.html
Copyright © 2020-2023  润新知