Spring- JdbcTemplate(整合数据源)

本文详细介绍了如何在Spring中整合JdbcTemplate,涉及常见数据源的使用,重点讲解了如何配置c3p0和Druid数据源,包括项目结构、pom.xml配置、bean.xml配置以及执行结果的展示。
摘要由CSDN通过智能技术生成

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值