1.1 常见数据源
在使用JdbcTemplate的时候,需要设置一个数据源对象,才能完成数据库操作
#常见的数据源:
内置数据源:
org.springframework.jdbc.datasource.DriverManagerDataSource
c3p0数据源:
com.mchange.v2.c3p0.ComboPooledDataSource
dbcp数据源:
org.apache.commons.dbcp.BasicDataSource
druid数据源:
com.alibaba.druid.pool.DruidDataSource
1.2 内置数据源
<?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.xsd">
<!--配置JdbcTemplate-->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<!--注入数据源对象-->
<property name="dataSource" ref="dataSource"></property>
</bean>
<!--配置数据源对象-->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<!--注入连接数据库的四个基本要素-->
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url