c3p0配置Spring


jdbc.properties

jdbcUrl=jdbc:mysql://localhost:3306/myoa?useUnicode=true&characterEncoding=utf-8
driverClass=com.mysql.jdbc.Driver
user=root
password=root

如果mysql亂碼就在properties加上:?useUnicode=true&characterEncoding=utf-8

如果實在xml中配置的話就:?useUnicode=true &   characterEncoding=utf-8

applicationContext.xml

<!-- 加載外部的properties配置文件 -->
    <context:property-placeholder location="classpath:jdbc.properties" />

    <!-- 配置數據庫連接池(c3p0) -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <!-- 基本信息 -->
        <property name="jdbcUrl" value="${jdbcUrl}"></property>
        <property name="driverClass" value="${driverClass}"></property>
        <property name="user" value="${username}"></property>
        <property name="password" value="${password}"></property>
        <!-- 其他配置 -->
        <!--初始化時獲取三個連接,取值應在minPoolSize與maxPoolSize之間。Default: 3 -->
        <property name="initialPoolSize" value="3"></property>
        <!--連接池中保留的最小連接數。Default: 3 -->
        <property name="minPoolSize" value="3"></property>
        <!--連接池中保留的最大連接數。Default: 15 -->
        <property name="maxPoolSize" value="5"></property>
        <!--當連接池中的連接耗盡的時候c3p0一次同時獲取的連接數。Default: 3 -->
        <property name="acquireIncrement" value="3"></property>
        <!-- 控制數據源內加載的PreparedStatements數量。如果maxStatements與maxStatementsPerConnection均為0,則緩存被關閉。Default: 0 -->
        <property name="maxStatements" value="8"></property>
        <!-- maxStatementsPerConnection定義了連接池內單個連接所擁有的最大緩存statements數。Default: 0 -->
        <property name="maxStatementsPerConnection" value="5"></property>
        <!--最大空閑時間,1800秒內未使用則連接被丟棄。若為0則永不丟棄。Default: 0 -->
        <property name="maxIdleTime" value="1800"></property>
    </bean>


    <!-- 配置SessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
        <property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
    </bean>

 

Java小生店鋪:

Pc端:http://shop125970977.taobao.com/index.htm

手機端:搜索 java小生店鋪

希望店鋪的資料能幫助到你!!!

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM