Spring 整合 JDBC 的方式
- 添加依赖
- 编写配置文件 db.properties
- bean.xml 配置修改
- 配置数据源
- 模板类配置
- 测试整合结果
案例实操
添加依赖
数据库驱动 jar 包
mysql-connector-java-5.1.25-bin.jar
数据库连接池相关 jar 包
c3p0-0.9.5.2.jar、mchange-commons-java-0.2.11.jar
Spring jdbc 相关 jar
spring-jdbc-4.3.2.RELEASE.jar、spring-tx-4.3.2.RELEASE.jar
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.9</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.39</version>
</dependency>
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1.2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.2.RELEASE</version>
</dependency>
<dependency