1、了解什么是druid 到官网 http://code.alibabatech.com/wiki/display/Druid/Home
2、使用实例:
结合spring,数据库dataSource 配置
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="url" value="${jdbc.url}" />
<property name="username"><value>${jdbc.username}</value></property>
<property name="password" value="${jdbc.password}" />
<property name="filters"><value>config</value></property>
<property name="maxActive"><value>1200</value></property>
<property name="initialSize"><value>5</value></property>
<property name="maxWait"><value>60000</value></property>
<property name="minIdle"><value>1</value></property>
<property name="timeBetweenEvictionRunsMillis"><value>60000</value></property>
<property name="minEvictableIdleTimeMillis"><value>300000</value></property>
<property name="validationQuery"><value>SELECT 'x'</value></property>
<property name="testWhileIdle"><value>true</value></property>
<property name="testOnBorrow"><value>false</value></property>
<property name="testOnReturn"><value>false</value></property>
<property name="poolPreparedStatements"><value>true</value></property>
<property name="maxOpenPreparedStatements"><value>20</value></property>
<property name="connectionProperties" value="config.decrypt=true" /> //数据库密码采用加密形式,结合filters 为config; 如果不要加密形式,filters为stat,本句不配置
</bean>
db.properties配置
jdbc.driverClassName =com.mysql.jdbc.Driver
jdbc.password =kuLilCru71y2LEUZxQLIkbKhVRk7jqPb/dA2D/zxjuozdFLyLfV83Mjsy7GMEwhxFAXOYuwqTii/9GUnXN53cg== //经过加密的密码
jdbc.url =jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&autoReconnect=true
jdbc.username =root
jdbc.maxActive =1200
jdbc.maxIdle =100
jdbc.maxWait =10000
数据库密码加密方式:
java -cp druid-0.2.23.jar com.alibaba.druid.filter.config.ConfigTools you_password当然你需要先下载druid 的jar包,官方网站上有下载的