✎
编程开发网
首页
C语言
C++
面试
Linux
函数
Windows
数据库
下载
搜索
当前位置:
首页
->
AI编程基础
->
数据库编程
第十七天dbutils的使用------CommonsDbUtils(Apache)第三方的:只是对JDBC编码进行了简单的封装(三)
2014-11-24 16:59:40
·
作者:
·
浏览:
4
标签:
十七
dbutils
使用
------CommonsDbUtils
Apache
第三方
只是
JDBC
编码
进行
简单
封装
; } } } //ColumnListHandler:将结果集中某一列的数据存放到List中。 投影 @Test public void test3() throws SQLException{ //数组中的元素就是记录的每列的值 List
list = qr.query("select * from account", new ColumnListHandler("name")); for(Object objs:list){ System.out.println(objs); } } //KeyedHandler(name):将结果集中的每一行数据都封装到一个Map<列名,列值>里,再把这些map再存到一个map里,其key为指定的key。 @Test public void test4() throws SQLException{ Map
> bmap= qr.query("select * from account", new KeyedHandler("id")); for(Map.Entry
> bme:bmap.entrySet()){ System.out.println("-----------------"); for(Map.Entry
lme:bme.getValue().entrySet()){ System.out.println(lme.getKey()+"="+lme.getValue()); } } } //MapHandler:将结果集中的第一行数据封装到一个Map里,key是列名,value就是对应的值 @Test public void test5() throws SQLException{ Map
map = qr.query("select * from account where id= ", new MapHandler(),1); for(Map.Entry
lme:map.entrySet()){ System.out.println(lme.getKey()+"="+lme.getValue()); } } //MapListHandler:将结果集中的每一行数据都封装到一个Map里,然后再存放到List @Test public void test6() throws SQLException{ List
> list= qr.query("select * from account", new MapListHandler()); for(Map
map:list){ System.out.println("-----------------"); for(Map.Entry
lme:map.entrySet()){ System.out.println(lme.getKey()+"="+lme.getValue()); } } } //ScalarHandler :只有一条记录的投影查询 select count(*) from account; @Test public void test7() throws SQLException{ // Object obj = qr.query("select * from account where id= ", new ScalarHandler("name"),1); // System.out.println(obj); Object obj = qr.query("select count(*) from account", new ScalarHandler(1)); int num = ((Long)obj).intValue(); System.out.println(num); } }
首页
上一页
1
2
3
下一页
尾页
3
/3/3