如何利用"c3p0"配置Oracle和MySQL连接
2010-07-20 10:08
746 查看
本文主要介绍了利用"c3p0"配置Oracle和MySQL连接的两段示例代码,大家在此
基础上可以根据各自的实际情况进行相应的修改。
一、连接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> |
<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& characterEncoding=utf-8&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> |
相关文章推荐
- MySQL 实例配置的"Apply security settings"错误 、 Java通过JDBC无法连接MySQL的 分析
- 如何利用**.ini配置文件获取MySQL连接信息
- 如何解决客户端与服务器端的连接(mysql) :"xxx.xxx.xxx.xxx" is not allowed to connect to this mysql server.
- ADO连接oracle数据"无法处理服务名"问题的处理!
- [SQL Server] 如何查询windows认证的用户连接数据库时的"权限/对应的登陆账号"(该账号是一个windows组)
- Oracle 连接的"+"
- jdbc连接mysql时报message from server: "Host '**' is not allowed to connect to this MySQL server"错误解决
- Informatica中利用ODBC连接Oracle、Sybase的配置方法
- 如何解决"应用程序无法启动,因为应用程序的并行配置不正确"问题
- ORACLE出现"关闭的连接"错误
- 如何连接判断字符新方法,如:where id0 and username="" and ......2006-6-8-3
- 解决连接MySQL时出现securityException异常,并且会有"That assembly does not allow partially trusted callers"的异常信息
- 如何配置 mysql 远程连接?
- jdbc的配置及jdbc连接常用数据库(mysql、sqlserver、Oracle)
- scala如何连接和操作mysql/oracle/sqlserver数据库
- 连接Oracle与mysql配置的不同之处
- 如何配置pl/sql (本地客户端)连接远程oracle服务器
- 如何连接oracle,mysql, SQL Server数据库(Java版)
- 如何解决 tomcat 下 oracle 缓冲池 读取 clob 字段内容 时的错误 "java.lang.ClassCastException: org.apache.commons.dbcp.DelegatingResultSet "