zoukankan
html css js c++ java
利用c3p0配置数据库连接
利用c3p0配置数据库连接
一.连接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
&
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
>
二.连接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
>
查看全文
相关阅读:
5.5,5.6
5.1,5.2
第四章.编程练习
多源最短路径--flody算法
Java 面试题
python 打包exe程序
sql优化
二叉树
todo: 队列、栈、散列集
java注解
原文地址:https://www.cnblogs.com/hehe520/p/6330273.html
最新文章
重装系统后Myeclipse遇到的项目配置问题--一个菜鸟的经历!
如何获取Input标签自定义属性的值?
如何取option自定义属性?
动态生成table
小积累-生成固定位数的随机数
判断浏览器类型及终端来源
利用iframe进行js跨域处理
为网页表单提交绑定回车快捷键
关于IE的几个兼容
视频播放器
热门文章
用jquery实现垂直左右居中
图片扩大缩小切换(类似微博图片查看)
css的特殊性笔记总结
第六章 编程练习
cctype中的字符函数
第六章 复习题
第六章
第五章 编程练习
使用new创建动态数组
vector 和array的用法
Copyright © 2011-2022 走看看