Package Demo.test;import Java.io.inputstream;import Java.sql.connection;import java.sql.sqlexception;import Java.util.properties;import Javax.sql.datasource;import Com.alibaba.druid.pool.druiddatasourcefactory;public Class Dbutil {private static DataSource ds = NULL; static {try{InputStream in = DBUtil.class.getClassLoader (). Getresou Rceasstream ("Ds.properties"); Properties Props = new properties (); Props.load (in); ds = Druiddatasourcefactory.createdatasource (props); }catch (Exception ex) {ex.printstacktrace (); }} public static Connection OpenConnection () throws sqlexception{return Ds.getconnection (); }} ds.properties content: driverclassname = Oracle.jdbc.driver.OracleDriverurl = Jdbc:oracle:thin:@127.0.0.1:1521:o Rclusername = ******password = ******initialsize = 5maxActive = 10minIdle = 3maxWait = 60000removeAbandoned = Trueremoveab AndonedtimeoUT = 180timeBetweenEvictionRunsMillis = 60000minEvictableIdleTimeMillis = 300000validationQuery = SELECT 1 from DUALTESTW Hileidle = True Testonborrow = Falsetestonreturn = Falsepoolpreparedstatements = Truemaxpoolpreparedstatementperconnectionsize = 50filters = Stat Spring-based configuration: <bean id= "Druiddatasource" class= " Com.alibaba.druid.pool.DruidDataSource "init-method=" Init "destroy-method=" Close "> <!--database basic information Configuration--&G T <property name= "Driverclassname" value= "${oracle.driver}"/> <property name= "url" value= "${oracle.url}"/& Gt <property name= "username" value= "${oracle.username}"/> <property name= "password" value= "${oracle.password } "/> <!--initialize the number of connections--<property name=" InitialSize "value=" ${druid.initialsize} "/> &L t;! --Maximum concurrent connections--<property name= "maxactive" value= "${druid.maxactive}"/> <!--maximum idle connections-- <property name= "Maxidle" value= "${druid.maxIdle} "/> <!--minimum number of idle connections--<property name=" Minidle "value=" ${druid.minidle} "/> <!- -Configure Get Connection Wait timeout time-<property name= "maxwait" value= "${druid.maxwait}"/> <!--time limit is recycled-- <property name= "removeabandoned" value= "${druid.removeabandoned}"/> <!--longer than the time limit;--& Lt;property name= "Removeabandonedtimeout" value= "${druid.removeabandonedtimeout}"/> <!--configuration interval to detect Closed idle connection, in milliseconds-<property name= "Timebetweenevictionrunsmillis" value= "${druid.timebetweenevictionrunsmillis } "/> <!--Configure the minimum lifetime of a connection in the pool, in milliseconds--and <property name=" Minevictableidletimemillis "value=" ${druid . Minevictableidletimemillis} "/> <!--is used to detect whether a connection is valid for SQL, a query statement is required--<property name=" Validationquer Y "value=" ${druid.validationquery} "/> <!--to request connection detection--<property name=" Testwhileidle "value=" ${druid.testwhileidle} "/> <!--perform validationquery to detect if connection is valid, configure TRUE to degrade performance-<property name= "Testonborrow" value= "${dr Uid.testonborrow} "/> <!--to return the connection when the Validationquery detection connection is valid, configured to true degrades performance and <property name=" test OnReturn "value=" ${druid.testonreturn} "/> <!--open Pscache and specify the size of Pscache on each connection--<property name = "Poolpreparedstatements" value= "${druid.poolpreparedstatements}"/> <property name= "maxPoolPreparedStatemen Tperconnectionsize "value=" ${druid.maxpoolpreparedstatementperconnectionsize} "/> <!--property type is a string, Using aliases to configure the extension, common plug-ins are: monitoring statistics with the Filter:stat log with filter:log4j defense SQL injection Filter:wall-- <property name= "Filters" value= "${druid.filters}"/> </bean> enabling Web monitoring statistics requires the following to be included in the Web application's XML: < Filter> <filter-name>DruidWebStatFilter</filter-name> <filter-class>com.alibaba.druid.suppo Rt.http.webstatfilter</filter-class> <init-param> <param-name>exclusions</param-name> <PARAM-VALUE>*.JS,*.GIF,*.JPG,*.P Ng,*.css,*.ico,/druid/*</param-value> </init-param></filter><filter-mapping> <filter- Name>druidwebstatfilter</filter-name> <url-pattern>/*</url-pattern></filter-mapping> <servlet> <servlet-name>DruidStatView</servlet-name> <servlet-class> Com.alibaba.druid.support.http.statviewservlet</servlet-class></servlet><servlet-mapping> <servlet-name>DruidStatView</servlet-name> <url-pattern>/druid/*</url-pattern></ servlet-mapping> Access Monitoring page: http://ip:port/projectName/druid/index.html
Druid Connection Pool Configuration