程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> 關於MYSQL數據庫 >> 利用“c3p0“配置數據庫連接的實例腳本

利用“c3p0“配置數據庫連接的實例腳本

編輯:關於MYSQL數據庫

一.連接MySQL數據庫

<bean id="dataSource"
        class="com.mchange.v2.c3p0.ComboPooledDataSource"
        destroy-method="close" abstract="false" singleton="true"
        lazy-init="default" autowire="default" dependency-check="default">
        <property name="driverClass">
            <value>com.mysql.jdbc.Driver</value>
        </property>
        <property name="jdbcUrl">
            <value>jdbc:mysql://192.168.0.1/databasename?

      useUnicode=true&amp;characterEncoding=utf-8&amp;

      autoReconnect=true</value>
        </property>
        <property name="user">
            <value>username</value>
        </property>
        <property name="password">
            <value>passWord</value>
        </property>
        <property name="minPoolSize">
            <value>10</value>
        </property>
        <property name="maxPoolSize">
            <value>20</value>
        </property>
        <property name="initialPoolSize">
            <value>10</value>
        </property>
    </bean>
    <bean id="sessionFactory"
        class="org.springframework.
   orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource">
            <ref bean="dataSource"></ref>
        </property>
        <property name="hibernatePropertIEs">
            <props>
                <prop key="hibernate.dialect">
                    org.hibernate.dialect.MySQLDialect
                </prop>
                <prop key="hibernate.show_sql">
                    false
                </prop>
                <prop key="hibernate.generate_statistics">true</prop>
                <prop key="hibernate.cache.use_query_cache">
                    true
                </prop>
                <prop key="hibernate.cache.use_second_level_cache">
                    true
                </prop>
                <prop key="hibernate.cache.provider_class">
                    net.sf.ehcache.hibernate.EhCacheProvider
                </prop>
                <prop key="hibernate.connection.provider_class">
                    org.hibernate.connection.C3P0ConnectionProvider
                </prop>
                <prop key="hibernate.query.substitutions">
                    true 1, false 0, yes 'Y', no 'N'
                </prop>
                <prop
                    key="hibernate.bytecode.use_reflection_optimizer">
                    true
                </prop>
                <prop key="hibernate.use_outer_join">true</prop>
                <prop key="hibernate.prepare_sql">true</prop>
                <prop key="hibernate.query.factory_class">
                    org.hibernate.hql.ast.ASTQueryTranslatorFactory
                </prop>
            </props>
        </property>

        <property name="mappingResources">
            <list>
                <value>xxx/xx/xx.hbm.xml</value>
                <value>xxx/xx/xx.hbm.XML</value>
            </list>
        </property>
    </bean>

二.連接Oracle數據庫

<bean id="dataSource"
        class="com.mchange.v2.c3p0.ComboPooledDataSource"
        destroy-method="close" abstract="false" singleton="true"
        lazy-init="default" autowire="default" dependency-check="default">
        <property name="driverClass">
            <value>oracle.jdbc.driver.OracleDriver</value>
        </property>
        <property name="jdbcUrl">
            <value>jdbc:oracle:thin:@192.168.0.1:1521:orcl</value>
        </property>
        <property name="user">
            <value>username</value>
        </property>
        <property name="password">
            <value>passWord</value>
        </property>
        <property name="minPoolSize">
            <value>10</value>
        </property>
        <property name="maxPoolSize">
            <value>20</value>
        </property>
        <property name="initialPoolSize">
            <value>10</value>
        </property>
    </bean>

    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource">
            <ref bean="dataSource"></ref>
        </property>
        <property name="hibernatePropertIEs">
            <props>
                <prop key="hibernate.dialect">
                    org.hibernate.dialect.OracleDialect
                </prop>
                <prop key="hibernate.show_sql">
                    false
                </prop>
                <prop key="hibernate.generate_statistics">true</prop>
                <prop key="hibernate.cache.use_query_cache">
                    true
                </prop>
                <prop key="hibernate.cache.use_second_level_cache">
                    true
                </prop>
                <prop key="hibernate.cache.provider_class">
                    net.sf.ehcache.hibernate.EhCacheProvider
                </prop>
                <prop key="hibernate.connection.provider_class">
                    org.hibernate.connection.C3P0ConnectionProvider
                </prop>
                <prop key="hibernate.query.substitutions">
                    true 1, false 0, yes 'Y', no 'N'
                </prop>
                <prop
                    key="hibernate.bytecode.use_reflection_optimizer">
                    true
                </prop>
                <prop key="hibernate.use_outer_join">true</prop>
                <prop key="hibernate.prepare_sql">true</prop>
                <prop key="hibernate.query.factory_class">
                    org.hibernate.hql.ast.ASTQueryTranslatorFactory
                </prop>
            </props>
        </property>

        <property name="mappingResources">
            <list>
                <value>xxx/xx/xx.hbm.xml</value>
                <value>xxx/xx/xx.hbm.XML</value>
            </list>
        </property>
    </bean>
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved