dbUtils 结果集处理器介绍 | 学习笔记

简介: 快速学习 dbUtils 结果集处理器介绍

开发者学堂课程【JDBC 数据库开发进阶dbUtils 结果集处理器介绍】学习笔记,与课程紧密联系,让用户快速学习知识。

课程地址https://developer.aliyun.com/learning/course/32/detail/691


dbUtils 结果集处理器介绍


内容介绍

一.update 方法

二.query 方法

三.开始测试


一.update 方法

int update( string sqlobject, params) 可执行增、删改语句

int update( connection con, String aql, Object... params) 需要调用者提供 Connection,这说明本方法不再管 Cesnection,支持事务!

 

二.query 方法:

T query( String sql, ReaultSetHandler rsh, Object…params) 可执行查询

它会先得到 ResultSet,然后请用 rsh handle()rs 转换成需要的类型!

T update( Connection con, String aql, ResultSetHadler rsh ,Object... params) 支持事务。

 

三.开始测试

eOverride

public stu handle(Resultset) throws SQLException

TODO Auto-generated method otub

return null;

/执行 query()方法,需要给出结果集处理器,ResultsetHandler 的实现类对象

/我们给的是 BeanHandler,它实现了 ReaultsetHandler

它需要一个类型,然后它会把中的数据封装到指定类型的 iavabean 对象中,然后返回 avabea

stu stu. query(, new BeanHandler(stu. class), params):

8yatem.out.printIn(atu);

aTest

publie void fun3() throws Exception

QueryRunner gr new QueryRunner(JdbcUtila.getDataSource()

string sql ="select from t stu";

Liat atuliat qr. query(aql, new BeanLiatHandler(stu.class))

syatem. out. printIn (atuliat)

@Test

publia void fun3() throws Exception

QueryRunner qr new QueryRunner(Jdbeutils. getDataSource()

string aql ="aelect from t atu":

List stuList qr.query (aql, new BeantistHandler(.olass))

Syatem.out.printIn()

/

MapHandler 的应用,它是单行处理器,把一行转换成一个 ap 对象 ethrowa SQLException

/

public void fun4() throws SQLException

QueryRunner gr new QueryRunner (JdbeUtils. getDataSource()

String agl =" from t atu where id=?";

object[] params =(1001):

Map map qr. query(, new MapHandler () parama);

Syatem.out. println(map)

ava. stuav

public void funi()throws SQmException

QueryRunner qr new QueryRunner(Jdbeutils. getDatasource()

string agl "aelect from t atu where aid=?":

object[] params ={10011:

Map map qr.query (ag1, new MapHandler(), parama):

System. out. printIn(map)

/

MapLiatHandler,它是多行处理器把每行都转换成一个 Map ,iat

throws SQLException

QTest

public void fun5() throws SQLException

QueryRunner gr new QueryRunrJdlbcUtila. getDataSo

string sql "select from t atu";

Liat mapLiat qr. qughy (agl, new MapLiatHandler ()

Syatem. out. printIn(maptiat)

publie void fun5() throws SQLException

QueryRunner qr new QueryRunnerJdbcUtila. gotDataSource())

string sql "select from t_stu";

List> maplist. query(, new MapLiatHandler (

system.out.printIn(mapList)

8calarHandler,它是单行单列时使用,最为合适

9throws SQLException

@Test

public void fun6() throws SQLException

QueryRunner gr new QueryRunner(JdbcUtils. getDataSource()

string sql "select count (* from tatu";

object obj. query (aql new SealarHandler()

Syatem.out.printIn(obj)

相关文章
|
5月前
|
SQL Java 数据库连接
由于你在执行MyBatis的查询时出现的问题
由于你在执行MyBatis的查询时出现的问题
44 1
|
Java 数据库连接 数据库
强大:MyBatis ,三种流式查询方法
流式查询指的是查询成功后不是返回一个集合而是返回一个迭代器,应用每次从迭代器取一条查询结果。流式查询的好处是能够降低内存使用。
强大:MyBatis ,三种流式查询方法
|
8月前
|
Java 数据库连接 数据库
Mybatis复杂结果集映射(详细)
Mybatis复杂结果集映射(详细)
49 0
|
10月前
|
SQL Java 数据库连接
【MyBatis学习笔记 三】结果集映射、日志处理及分页查询
【MyBatis学习笔记 三】结果集映射、日志处理及分页查询
79 0
|
11月前
|
缓存 安全 Java
MyBatis源码-解读Executor的三个实现类之BatchExecutor(批处理执行器)
MyBatis源码-解读Executor的三个实现类之BatchExecutor(批处理执行器)
191 0
|
SQL 存储 XML
详解MyBatis中Executor执行SQL语句的过程
在详解MyBatis的SqlSession获取流程文章中已经知道,MyBatis中获取SqlSession时会创建执行器Executor并存放在SqlSession中,通过SqlSession可以获取映射接口的动态代理对象,动态代理对象的生成可以参考详解MyBatis加载映射文件和动态代理,可以用下图进行概括。
206 0
|
SQL Java 关系型数据库
浅谈MyBatis批量插入方法,10w条数据处理仅需2秒
浅谈MyBatis批量插入方法,10w条数据处理仅需2秒
852 0
浅谈MyBatis批量插入方法,10w条数据处理仅需2秒
|
SQL XML 缓存
第05篇:Mybatis的SQL执行流程分析
前面我们知道了Mybatis是如何进行代理的, 但是最终 `PlainMethodInvoker` 中是如何将参数转组装成Sql,并执行处理Sql返回值的地方还都没看到。本篇我们就带着如下三个问题开始我们的探索吧。
329 0
|
存储 SQL 设计模式
【源码解析】MyBatis结果集映射和参数绑定
MyBatis结果集映射源码解析,详细分析了 handleRowValuesForSimpleResultMap() 等方法实现映射的核心步骤
【源码解析】MyBatis结果集映射和参数绑定
|
SQL XML Java
MyBatis - 分页之四大方式(数组、SQL、拦截器,RowBounds)
MyBatis - 分页之四大方式(数组、SQL、拦截器,RowBounds)
370 0
MyBatis - 分页之四大方式(数组、SQL、拦截器,RowBounds)