eclipse web项目配置c3p0连接池
时间: 2023-07-16 13:12:36 浏览: 189
在 Eclipse 中配置 c3p0 连接池的步骤如下:
1. 在项目中添加 c3p0 依赖:
```xml
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>${c3p0.version}</version>
</dependency>
```
2. 在项目中创建 c3p0 的配置文件:
在项目的 src 目录下创建一个名为 `c3p0-config.xml` 的文件,并添加以下内容:
```xml
<?xml version="1.0" encoding="UTF-8"?>
<c3p0-config>
<default-config>
<!-- 数据库驱动类名 -->
<driverClass>com.mysql.jdbc.Driver</driverClass>
<!-- 数据库连接地址 -->
<jdbcUrl>jdbc:mysql://localhost:3306/test</jdbcUrl>
<!-- 数据库用户名 -->
<user>root</user>
<!-- 数据库密码 -->
<password>123456</password>
<!-- 初始化连接数 -->
<initialPoolSize>5</initialPoolSize>
<!-- 最小连接数 -->
<minPoolSize>5</minPoolSize>
<!-- 最大连接数 -->
<maxPoolSize>20</maxPoolSize>
<!-- 超时等待时间 -->
<checkoutTimeout>5000</checkoutTimeout>
<!-- 连接回收时间 -->
<maxIdleTime>1800</maxIdleTime>
</default-config>
</c3p0-config>
```
3. 在代码中获取 c3p0 数据库连接:
```java
ComboPooledDataSource dataSource = new ComboPooledDataSource();
dataSource.setConfigName("default-config");
Connection connection = dataSource.getConnection();
```
其中,`setConfigName()` 方法中的参数为配置文件中的 `<default-config>` 标签的名称。
以上就是在 Eclipse 中配置 c3p0 连接池的步骤,希望对你有所帮助。
阅读全文
相关推荐

















