Spring和C3P0数据连接池使用
书山有路勤为径
工具:
- MyEclipse
- JDK1.7
- Oracle数据库
步骤
1.在MyEclipse中新建Web项目
2.添加jar包到WebRoot\WEB-INF\lib目录下
-Spring-3.2.0 jar包
-c3p0.jar包
-数据库驱动包
-其它依赖jar包
3.spring配置文件(application.xml)
<!-- 文件名:application.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!--读取其它配置文件,这里读取db.properties文件 -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:db.properties"/>
</bean>
<!-- 配置数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${db_driverClass}"/>