7.Spring连接数据库

applicationContext:

<?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"
       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">

	<!-- 先配置连接池 -->
	<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
		<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
		<property name="url" value="jdbc:mysql://localhost:3306/spring_day02"></property>
		<property name="username" value="root"></property>
		<property name="password" value="mjl123"></property>
	</bean>
	
	<!-- DBCP连接池 -->
	<bean id="dataSource1" class="org.apache.commons.dbcp.BasicDataSource">
		<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
		<property name="url" value="jdbc:mysql://localhost:3306/spring_day02"></property>
		<property name="username" value="root"></property>
		<property name="password" value="mjl123"></property>
	</bean>
	
	<!-- C3P0连接池 -->
	<bean id="dataSource2" class="com.mchange.v2.c3p0.ComboPooledDataSource">
	 	<property name="driverClass" value="com.mysql.jdbc.Driver"></property>
	 	<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/spring_day02"></property>
		<property name="user" value="root"></property>
		<property name="password" value="mjl123"></property>
	</bean>
</beans>

  

posted @ 2018-03-19 17:38  一日看尽长安花cxjj  阅读(144)  评论(0)    收藏  举报