spring中的JdbcTemplate——JdbcTemplate的最基本用法
生活随笔
收集整理的這篇文章主要介紹了
spring中的JdbcTemplate——JdbcTemplate的最基本用法
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
spring中的JdbcTemplate
JdbcTemplate的作用:?它就是用于和數(shù)據(jù)庫交互的,實現(xiàn)對表的CRUD操作
JdbcTemplate 概述
它是 spring 框架中提供的一個對象,是對原始 Jdbc API 對象的簡單封裝。spring 框架為我們提供了很多的操作模板類。 操作關(guān)系型數(shù)據(jù)的:JdbcTemplate
HibernateTemplate
操作 nosql 數(shù)據(jù)庫的:RedisTemplate
操作消息隊列的:JmsTemplate
在 spring-jdbc-5.0.2.RELEASE.jar 中,在導(dǎo)包的時候,除了要導(dǎo)入這個 jar 包 外,還需要導(dǎo)入一個 ? ? spring-tx-5.0.2.RELEASE.jar(它是和事務(wù)相關(guān)的)。JdbcTemplate的最基本用法
JdbcTemplateDemo1.java
package com.itheima.jdbctemplate;import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.DriverManagerDataSource;/*** JdbcTemplate的最基本用法*/ public class JdbcTemplateDemo1 {public static void main(String[] args) {//準(zhǔn)備數(shù)據(jù)源:spring的內(nèi)置數(shù)據(jù)源DriverManagerDataSource ds = new DriverManagerDataSource();ds.setDriverClassName("com.mysql.jdbc.Driver");ds.setUrl("jdbc:mysql://localhost:3306/eesy");ds.setUsername("root");ds.setPassword("root");//1.創(chuàng)建JdbcTemplate對象JdbcTemplate jt = new JdbcTemplate();//給jt設(shè)置數(shù)據(jù)源jt.setDataSource(ds);//2.執(zhí)行操作jt.execute("insert into account(name,money) values('ccc',1000)");} }?
總結(jié)
以上是生活随笔為你收集整理的spring中的JdbcTemplate——JdbcTemplate的最基本用法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Spring基于注解的AOP配置
- 下一篇: JdbcTemplate的CRUD操作