利用c3p0配置数据库连接
<beanid="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close"abstract="false"singleton="true"
lazy-init="default"autowire="default"dependency-check="default">
<propertyname="driverClass">
<value>com.mysql.jdbc.Driver</value>
</property>
<propertyname="jdbcUrl">
<value>jdbc:mysql://192.168.0.1/databasename?useUnicode=true&characterEncoding=utf-8&autoReconnect=true</value>
</property>
<propertyname="user">
<value>username</value>
</property>
<propertyname="password">
<value>password</value>
</property>
<propertyname="minPoolSize">
<value>10</value>
</property>
<propertyname="maxPoolSize">
<value>20</value>
</property>
<propertyname="initialPoolSize">
<value>10</value>
</property>
</bean>
<beanid="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<propertyname="dataSource">
<refbean="dataSource"></ref>
</property>
<propertyname="hibernateProperties">
<props>
<propkey="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<propkey="hibernate.show_sql">
false
</prop>
<propkey="hibernate.generate_statistics">true</prop>
<propkey="hibernate.cache.use_query_cache">
true
</prop>
<propkey="hibernate.cache.use_second_level_cache">
true
</prop>
<propkey="hibernate.cache.provider_class">
net.sf.ehcache.hibernate.EhCacheProvider
</prop>
<propkey="hibernate.connection.provider_class">
org.hibernate.connection.C3P0ConnectionProvider
</prop>
<propkey="hibernate.query.substitutions">
true1,false0,yes'Y',no'N'
</prop>
<prop
key="hibernate.bytecode.use_reflection_optimizer">
true
</prop>
<propkey="hibernate.use_outer_join">true</prop>
<propkey="hibernate.prepare_sql">true</prop>
<propkey="hibernate.query.factory_class">
org.hibernate.hql.ast.ASTQueryTranslatorFactory
</prop>
</props>
</property>
<propertyname="mappingResources">
<list>
<value>xxx/xx/xx.hbm.xml</value>
<value>xxx/xx/xx.hbm.xml</value>
</list>
</property>
</bean>
<beanid="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close"abstract="false"singleton="true"
lazy-init="default"autowire="default"dependency-check="default">
<propertyname="driverClass">
<value>oracle.jdbc.driver.OracleDriver</value>
</property>
<propertyname="jdbcUrl">
<value>jdbc:oracle:thin:@192.168.0.1:1521:orcl</value>
</property>
<propertyname="user">
<value>username</value>
</property>
<propertyname="password">
<value>password</value>
</property>
<propertyname="minPoolSize">
<value>10</value>
</property>
<propertyname="maxPoolSize">
<value>20</value>
</property>
<propertyname="initialPoolSize">
<value>10</value>
</property>
</bean>
<beanid="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<propertyname="dataSource">
<refbean="dataSource"></ref>
</property>
<propertyname="hibernateProperties">
<props>
<propkey="hibernate.dialect">
org.hibernate.dialect.OracleDialect
</prop>
<propkey="hibernate.show_sql">
false
</prop>
<propkey="hibernate.generate_statistics">true</prop>
<propkey="hibernate.cache.use_query_cache">
true
</prop>
<propkey="hibernate.cache.use_second_level_cache">
true
</prop>
<propkey="hibernate.cache.provider_class">
net.sf.ehcache.hibernate.EhCacheProvider
</prop>
<propkey="hibernate.connection.provider_class">
org.hibernate.connection.C3P0ConnectionProvider
</prop>
<propkey="hibernate.query.substitutions">
true1,false0,yes'Y',no'N'
</prop>
<prop
key="hibernate.bytecode.use_reflection_optimizer">
true
</prop>
<propkey="hibernate.use_outer_join">true</prop>
<propkey="hibernate.prepare_sql">true</prop>
<propkey="hibernate.query.factory_class">
org.hibernate.hql.ast.ASTQueryTranslatorFactory
</prop>
</props>
</property>
<propertyname="mappingResources">
<list>
<value>xxx/xx/xx.hbm.xml</value>
<value>xxx/xx/xx.hbm.xml</value>
</list>
</property>
</bean>
本文介绍如何使用 C3P0 连接池配置 MySQL 和 Oracle 数据库,并结合 Hibernate 实现高效的数据库交互。文章详细展示了配置文件中各参数的意义及设置方法。
1056

被折叠的 条评论
为什么被折叠?



