JDBC Template - 入门篇
发布日期:2021-06-30 23:47:24
浏览次数:2
分类:技术文章
本文共 3090 字,大约阅读时间需要 10 分钟。
import com.imooc.sc.entity.Student;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import org.springframework.jdbc.core.JdbcTemplate;import org.springframework.jdbc.core.RowMapper;import java.sql.ResultSet;import java.sql.SQLException;import java.util.ArrayList;import java.util.Date;import java.util.List;import java.util.Map;public class Test { private JdbcTemplate jdbcTemplate; { ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml"); jdbcTemplate = (JdbcTemplate)context.getBean("jdbcTemplate"); } public void testExecute(){ jdbcTemplate.execute("create table user1(id int,name varchar(20))"); } public void testUpdate(){ String sql = "insert into student(name,sex) values(?,?)"; jdbcTemplate.update(sql,new Object[]{"张飞","男"}); } public void testUpdate2(){ String sql = "update student set sex=? where id=?"; jdbcTemplate.update(sql,"女",1003); } public void testBatchUpdate(){ String[] sqls={ "insert into student(name,sex) values('关羽','女')", "insert into student(name,sex) values('刘备','男')", "update student set sex='女' where id=2001" }; jdbcTemplate.batchUpdate(sqls); } public void testBatchUpdate2(){ String sql = "insert into selection(student,course) values(?,?)"; List
转载地址:https://lux-sun.blog.csdn.net/article/details/84346863 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
感谢大佬
[***.8.128.20]2024年04月08日 07时07分03秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
衡量代码质量的唯一有效标准:WTF/min
2019-05-01
一个网络请求的历险之旅
2019-05-01
Google 为什么把几十亿行代码放在一个库
2019-05-01
Erlang 之父 Joe Armstrong 去世
2019-05-01
来不及了,世界读书日,送10本书
2019-05-01
速来,上期中奖名单
2019-05-01
一名 Google 工程师的大数据处理经验
2019-05-01
命令行神器 Click 快速上手
2019-05-01
『二十次幂』开发手记
2019-05-01
30分钟学会pyecharts数据可视化
2019-05-01
从一个骗子身上学到的
2019-05-01
关于Python爬虫,这里有一条高效的学习路径
2019-05-01
Python学习指南,看这篇清晰多了!
2019-05-01
Oracle裁员,3点建议
2019-05-01
「忙」只是借口
2019-05-01
如果只有1小时学Python,看这篇就够了
2019-05-01
命名难,难于上青天
2019-05-01
记一件小事
2019-05-01
一个牛逼的数据库操作命令行工具:mycli
2019-05-01
掌握 Python 爬虫的所有技巧,都在这里!
2019-05-01