1 Druid Introduction
Druid is a project on Alibaba's Open source platform, which consists of a database connection pool, a plug-in framework, and a SQL parser. The main purpose of this project is to extend some of the limitations of JDBC, allowing programmers to implement specific requirements such as requesting credentials for key services, statistical SQL information, SQL Performance collection, SQL injection checking, SQL translation, and so on, which programmers can customize to achieve their own functionality.
Druid is currently the best database connection pool, in terms of functionality, performance, scalability, and more than other database connection pools, including DBCP, C3P0, BONECP, Proxool, JBoss DataSource. Druid has deployed more than 600 applications at Alibaba and has undergone a rigorous test of large-scale deployment of production environments over a year. features of the 2.Druid
1, replace DBCP and C3P0. Druid provides an efficient, powerful, and scalable database connection pool.
2, can monitor database access performance, Druid built-in provides a powerful statfilter plug-in, the ability to detailed statistics of SQL execution performance, which is useful for online analysis of database access performance.
3, Database password encryption. Write the database password directly in the configuration file, this is bad behavior, easy to lead to security issues. Both Druiddruiver and Druiddatasource support PasswordCallback.
4, SQL execution log, Druid provides different logfilter, can support common-logging, log4j and Jdklog, you can select the appropriate logfilter as needed to monitor the database access of your application.
5, extended JDBC, if you want to have the JDBC layer programming requirements, can be provided by the Druid filter mechanism, it is convenient to write the JDBC layer extension. 3.Druid How to configure Maven
<dependency>
<groupId>com.alibaba</groupId>
<artifactid>druid</artifactid >
<version>${druid-version}</version>
</dependency>
4.Druid Supported Databases
In theory, all databases that have JDBC drivers are supported. Actual tested MySQL support, large-scale use of Oracle support, large-scale use of SQL Server support Postgres support DB2 support H2 support for the Derby support SQLite support Sybase support 5. Configure Druiddat Asource
<bean id= "DataSource" class= "Com.alibaba.druid.pool.DruidDataSource" init-method= "Init" destroy-method= "Close" > <!--Basic property URL, user, password-<property name= "url" value= "${jdbc_url}"/> <proper Ty name= "username" value= "${jdbc_user}"/> <property name= "password" value= "${jdbc_password}"/> < ;! --Configuration initialization size, MIN, max---<property name= "InitialSize" value= "1"/> <property name= "Minidle" value= "1" /> <property name= "maxactive" value= "/> <!--configuration Get connection Wait timeout time--<property name=" M Axwait "value=" 60000 "/> <!--configuration interval to detect idle connections that need to be closed, in milliseconds--and <property name= ' Timebetweenevic Tionrunsmillis "value=" 60000 "/> <!--Configure the minimum lifetime of a connection in the pool, in milliseconds--and <property name= ' Minevictableidle Timemillis "value=" 300000 "/> <property name=" validationquery "value=" select ' X ' "/> <property na Me= "Testwhileidle" value= "true" /> <property name= "Testonborrow" value= "false"/> <property name= "Testonreturn" value= "false"/&G
T <!--open Pscache, and specify the size of Pscache on each connection-<property name= "poolpreparedstatements" value= "true"/> < ;p roperty name= "maxpoolpreparedstatementperconnectionsize" value= "/> <!--Configuration Monitoring statistics interception filters--& Lt;property name= "Filters" value= "stat"/> </bean>
In general, you only need to modify InitialSize, Minidle, maxactive.
If Oracle is used, configuring poolpreparedstatements to True,mysql can be configured to False. A database with more sub-tables is recommended to be configured as false. 6. Configure _statfilter
<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> <filter> <filter-name>DruidWebStatFilter</filter-name> <filter-class> ;com.alibaba.druid.support.http.webstatfilter</filter-class> <init-param> <param-name>exclusio Ns</param-name> <param-value>*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*</param-value> </in it-param> <init-param> <param-name>profileEnable</param-name> <param-value>true </param-value> </init-param> <init-param> <param-name>principalcookiename</param- Name> <param-value>user_cookie</param-value> </init-param> <init-param> <param-name>principalSessionName</param-name>
<param-value>USER_SESSION</param-value> </init-param> </filter> <filter-mapping> <filter-name>DruidWebStatFilter</filter-name> <url-pattern>/*</url-pattern> </filter- Mapping>
7. Results show
7.1. Home
7.2 SQL Monitoring
Code Address