-
导入相关jar包
- 在xml文件中applicationContext.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" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- 配置jdbc内置连接池 --> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql:///springdate?useUnicode=true&characterEncoding=utf8" /> <property name="username" value="root" /> <property name="password" value="" /> </bean> <!-- dbcp的连接池配置 --> <bean id="dataSource1" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql:///springdate?useUnicode=true&characterEncoding=utf8"/> <property name="username" value="root"/> <property name="password" value=""/> </bean> <!-- C3P0连接池 --> <bean id="dataSource2" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="com.mysql.jdbc.Driver"/> <property name="jdbcUrl" value="jdbc:mysql:///springdate?useUnicode=true&characterEncoding=utf8"/> <property name="user" value="root"/> <property name="password" value=""/> </bean> <!-- 配置Spring的JDBC的模板========================= --> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> <property name="dataSource" ref="dataSource2" /> </bean> </beans>
Spring中JDBC.DBCP.C3P0连接池的配置
猜你喜欢
转载自blog.csdn.net/qq_38474916/article/details/82109690
今日推荐
周排行