如何利用”c3p0″配置Oracle和MySQL串連

來源:互聯網
上載者:User

本文主要介紹了利用"c3p0"配置Oracle和MySQL串連的兩段範例程式碼,大家在此
基礎上可以根據各自的實際情況進行相應的修改。

一、串連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>

二.串連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>

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.