JdbcTemplate(概念和准备)
目录
1.什么是jdbcTemplate
2.使用前准备工作:
(1)引入相关jar包
(2)在spring 配置文件配置数据库连接池
(3)配置jdbcTemplate 对象,注入 DataSource
(4)创建service类,创建dao类,在dao 里面注入 jdbcTemplate 对象
步骤一:
步骤二:
步骤三:
1.什么是jdbcTemplate
概念:jdbcTemplate是Spring框架对JDBC进行封装,使用jdbcTemplate 方便实现对数据库进行操作
2.使用前准备工作:
(1)引入相关jar包
通过maven导入
(2)在spring 配置文件配置数据库连接池
相当于把数据导入到一个数据库连接池,在这个池里面进行连接会降低资源消耗
<?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"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"><!--数据库连接池--><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close"><property name="url" value="jdbc:mysql://localhost:3306/user_db?useSSL=false&useUnicode=true&characterEncoding=UTF-8"/><property name="username" value="root"/><property name="password" value="sise"/><property name="driverClassName" value="com.mysql.jdbc.Driver"/></bean></beans>
(3)配置jdbcTemplate 对象,注入 DataSource
由spring提供的jdbcTemplate对象,需要将数据元信息DataSource注入到jdbcTemplate对象中
<?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"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"><!-- 开启组件扫描--><context:component-scan base-package="org.example"></context:component-scan>
<!--数据库连接池--><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close"><property name="url" value="jdbc:mysql://localhost:3306/user_db?useSSL=false&useUnicode=true&characterEncoding=UTF-8"/><property name="username" value="root"/><property name="password" value="sise"/><property name="driverClassName" value="com.mysql.jdbc.Driver"/></bean><!-- 创建jdbcTemplate对象--><bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<!--需要注入数据源信息--><property name="dataSource" ref="dataSource"></property></bean>
</beans>
(4)创建service类,创建dao类,在dao 里面注入 jdbcTemplate 对象
步骤一:
在配置文件中开启组件扫描
步骤二:
Service:
步骤三:
dao:
以上就是Spring和jdbcTemplate之间的准备工作,下一章,我们继续完善实现代码
JdbcTemplate(概念和准备)相关推荐
- Spring5框架基础详解(五)(JdbcTemplate概念和准备、jdbcTemplate操作数据库添加功能、修改和删除功能、查询功能)
文章目录 一.JdbcTemplate是什么和准备工作 1.1.引入相关maven依赖 1.2在spring配置文件配置数据库连接 1.3配置JdbcTemplate对象,注入DateSource 1 ...
- c3p0和jdbctemplate配置oracle集群rac,C3P0连接池、DRUID连接池和JdbcTemplate
目录 一.C3P0连接池 1.C3P0连接池简介 2.常用的配置参数 3.C3P0连接池基本使用 (1)C3P0配置文件 (2)API介绍 4.使用步骤 二.DRUID连接池 1. DRUID简介 2 ...
- C3P0连接池、DRUID连接池和JdbcTemplate
目录 一.C3P0连接池 1.C3P0连接池简介 2.常用的配置参数 3.C3P0连接池基本使用 (1)C3P0配置文件 (2)API介绍 4.使用步骤 二.DRUID连接池 1. DRUID简介 2 ...
- JAVAEE框架之Spring JdbcTemplate
七.JdbcTemplate 概念:Spring对数据库的操作在jdbc上面做了深层次的封装,使用spring的注入功能,可以把DataSource注册到JdbcTemplate之中.目的是使JD ...
- 在spring中使用JdbcTemplate进行数据库管理操作
JdbcTemplate 1.JdbcTemplate概念及使用 a)Spring 框架对 JDBC 进行封装,使用 JdbcTemplate 方便实现对数据库操作 b)引入相关 jar 包 ...
- 学习笔记——spring5概念和原理
文章目录 一. spring5概述和原理 Spring5 框架概述 Spring5入门案例 IOC(概念和原理) IOC(BeanFactory 接口) IOC操作 Bean 管理(概念) IOC操作 ...
- JdbcTemplate介绍
JdbcTemplate介绍 JdbcTemplate概念 使用JdbcTemplate的准备工作 操作数据库(增) 操作数据库 (修改和删除) 操作数据库 (查询) 查询返回某个值 查询返回对象 查 ...
- 001 spring5框架:java类工程,IOC:实体类表示表关系,AOP,JdbcTemplate模板,事务操作,Spring5 框架新功能:日志,为空注解,函数式风格,juint,Webflux
1. Spring5 框架(Spring5 Framework)介绍 1.1 概念 1.Spring 是轻量级的开源的 JavaEE 框架 2.Spring 可以解决企业应用开发的复杂性 3.Spri ...
- exploring spring
连续看 spring framework 两天了,总算对 spring 有一点点的了解了,也算是有那么一点点的收获吧,写点东西,也算是对理解概念做一番总结吧,初看 spring 的时候总是被它的两个主 ...
最新文章
- 组合计数 ---- 2020 EC final B. Rectangle Flip 2(枚举+组合计数)
- 自定义Sharepoint的登陆页面(2)
- 你们是不是真的很缺大数据工程师?
- STUN响应消息中添加MAPPED_ADDRESS
- CentOS 6.3下配置LVM(逻辑卷管理
- [2020-09-11 CQBZ/HSZX多校联测 T2] 泰拳警告(组合数+数学期望)
- Win11开始菜单没反应怎么办 Win11开始菜单点了没反应解决方法
- 2014025650《嵌入式程序设计》第一周学习总结
- gns3虚拟机服务器集群,GNS3中如何实现与Vmware Workstation连接
- 一篇讲完Java链表(单链表、循环链表和双向链表)
- 如何快速看懂英文论文?
- js前端生成excel文件(表格)并下载
- 内存设置无效: 内存预留 (sched.mem.min) 应该等于内存大小 (65536)
- c语言快速平方根算法,单片机开平方的快速算法
- 第五章 树16 AcWing 1628. 判断红黑树
- 网线哪几根是发送数据,哪几根是接收数据的?
- vi linux insert切换该行第一个字符,Linux之Vi命令讲解
- 从无到有:七步教你做数值(1)
- 美国宣布进入国家紧急状态!
- python+PIL批量制作淘宝主图(头图)及满屏水印添加
热门文章
- 性能调优:理解Set Statistics Time输出
- Spring Cache 配置及一些问题的解决
- 牛客网--19校招--俄罗斯方块
- tomcat linux环境变量,linux系统为什么需要配置tomcat环境变量
- js整体缩小网页_SEO网页优化的原则是什么?
- java判断优先级代码_java运算符的优先级
- scope参数错误或没有scope权限_SSM 单体框架 - 前端开发:用户和权限模块
- android壁纸居中,Android Launcher 如何实现壁纸居中
- mysql 命令 kill_MySQL之死锁检测
- security center拒绝访问_Steam被曝出0day提权漏洞,但厂商拒绝修复