xml configuration of 3 common database connection pools

Background: The connection pool is responsible for allocating, managing and releasing database connections, which can significantly improve the performance of database operations.

Main body: This mainly describes the xml configuration methods of three commonly used database connection pools (c3p0, dbcp, BoneCP).

Configuration environment: Maven+SSM

1.1 Connection pool one: c3p0

1.2  Guide package, pom.xml guide package

<dependency>
	<groupId>c3p0</groupId>
	<artifactId>c3p0</artifactId>
   <version>0.9.1.2</version>
</dependency>
1.3  Configure the connection pool of dataSource in spring-mybatis.xml
<bean id="dataSource" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close">  
        <property name="driverClass" value="com.mysql.jdbc.Driver" />  
        <property name="jdbcUrl" value="jdbc:mysql://106.15.200.190:3306/test?useUnicode=true&characterEncoding=UTF-8" />  
        <property name="username" value="root" />  
        <property name="password" value="root" />   
    </bean>  

2.1 Connection pool two: dbcp

2.2 Guide package

<dependency>
	<groupId>commons-dbcp</groupId>
	<artifactId>commons-dbcp</artifactId>
	<version>1.2.2</version>
</dependency>

2.3 Configure the connection pool of dataSource in spring-mybatis.xml

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"  
        destroy-method="close">  
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />  
        <property name="url" value="jdbc:mysql://106.15.200.190:3306/test?useUnicode=true&characterEncoding=UTF-8"/>  
        <property name="username" value="root" />  
        <property name="password" value="root"/>  
    </bean>

3.1 Connection Pool Two: BoneCP

<dependency>
	<groupId>com.jolbox</groupId>
	<artifactId>bonecp</artifactId>
	<version>0.8.0.RELEASE</version>
</dependency>

3.2 Configure the connection pool of dataSource in spring-mybatis.xml

<bean id="dataSource" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close">  
        <property name="driverClass" value="com.mysql.jdbc.Driver" />  
        <property name="jdbcUrl" value="jdbc:mysql://106.15.200.190:3306/test?useUnicode=true&characterEncoding=UTF-8" />  
        <property name="username" value="root" />  
        <property name="password" value="root" />   
</bean>  
The efficiency of c3p0 and dbcp is not much different. The efficiency of BoneCP will be much faster than the first two. This is a reservation, because I use BoneCP to do a simple login. The first two are slower, and the second time I click, I personally feel that the speed is not much different.
The above configuration does not carry out some detailed configuration of the connection pool, such as the maximum number of connections, the minimum number of connections, etc., if the project needs to be further configured, the default configuration is used without configuration. Also pay attention to the aliasing of the four major components of these three database connections.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326416901&siteId=291194637