Spring中jdbc.properties(db.properties)的用法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zqq_2016/article/details/86670657

常见几种数据库基本资源文件jdbc.properties的配置:

注意:localhost或改为ip地址,

          通用公式:以mysql为例:jdbc.mysql://localhost/数据库名称?useUnicode=true&characterEncoding=utf8(防止乱码)     

1.MySQL数据库:

mysql_driver=com.mysql.jdbc.Driver

mysql_url=jdbc:mysql://localhost/trys

mysql_user=root

mysql_password=root

2.SqlServer数据库:

sqlserver_driver=com.microsoft.sqlserver.jdbc.SQLServerDriver

sqlserver_url=jdbc:sqlserver://localhost:1433;databasename=trys

sqlserver_user=root

sqlserver_password=root

3.Oracle数据库:

oracle_driver=oracle.jdbc.driver.OracleDriver

oracle_url=jdbc:oracle:thin:@localhost:1521:trys

oracle_user=root

oracle_password=root

4.jdbc.properties比较全的其他配置:

######Druid配置
#初始化连接
jdbc.initialSize=10
#最大空闲连接
jdbc.maxIdle=20 

# jdbc.maxTotal=30
#最小空闲连接
jdbc.minIdle=5
#最大连接数量
jdbc.maxActive=50
#取得对象时是否进行验证,检查对象是否有效,默认为false
jdbc.testOnBorrow=true
#验证连接是否有效的SQL文
jdbc.validationQuery=select 1
#执行验证连接有效SQL文的超时时间
jdbc.validationQueryTimeout=100
#返回对象时是否进行验证,检查对象是否有效,默认为false
jdbc.testOnReturn=false
#空闲时是否进行验证,检查对象是否有效,默认为false
jdbc.testWhileIdle=true
#大于0 ,进行连接空闲时间判断,或为0,对空闲的连接不进行验证;默认30分钟 (毫秒)
jdbc.minEvictableIdleTimeMillis=1800000
#失效检查线程运行时间间隔,如果小于等于0,不会启动检查线程 (毫秒)
jdbc.timeBetweenEvictionRunsMillis=60000
#超时等待时间以毫秒为单位
#maxWait代表当Connection用尽了,多久之后进行回收丢失连接
jdbc.maxWait=1000
#是否在自动回收超时连接的时候打印连接的超时错误
#jdbc.logAbandoned=true
#是否自动回收超时连接
jdbc.removeAbandoned=true
#超时时间(以秒数为单位)
#设置超时时间有一个要注意的地方,超时时间=现在的时间-程序中创建Connection的时间,如果 maxActive比较大,比如超过100,那么removeAbandonedTimeout可以设置长一点比如180,也就是三分钟无响应的连接进行 回收,当然应用的不同设置长度也不同。
jdbc.removeAbandonedTimeout=180
#打开PSCache,并且指定每个连接上PSCache的大小
jdbc.maxPoolPreparedStatementPerConnectionSize=20
jdbc.poolPreparedStatements=true
#配置监控统计拦截的filters
jdbc.filters=slf4j

猜你喜欢

转载自blog.csdn.net/zqq_2016/article/details/86670657
今日推荐