public class HBaseDML {
//静态属性
public static Connection conn = HBaseConnection2.conn;

//添加数据
public void putCell(Contract contract) {
try {
Table table = conn.getTable(TableName.valueOf("test1", "Contract"));
Put put = new Put(Bytes.toBytes(contract.getRowkey()));
put.addColumn(
Bytes.toBytes("info"), Bytes.toBytes("name"), Bytes.toBytes(contract.getName()))
.addColumn(Bytes.toBytes("info"), Bytes.toBytes("rowkey"), Bytes.toBytes(contract.getAddress()))
.addColumn(Bytes.toBytes("info"), Bytes.toBytes("address"), Bytes.toBytes(contract.getAddress()))
.addColumn(Bytes.toBytes("info"), Bytes.toBytes("place"), Bytes.toBytes(contract.getPlace()))
.addColumn(Bytes.toBytes("info"), Bytes.toBytes("email"), Bytes.toBytes(contract.getEmail()))
.addColumn(Bytes.toBytes("info"), Bytes.toBytes("faren"), Bytes.toBytes(contract.getFaren()))
.addColumn(Bytes.toBytes("info"), Bytes.toBytes("contacts"), Bytes.toBytes(contract.getContacts()))
.addColumn(Bytes.toBytes("info"), Bytes.toBytes("phone"), Bytes.toBytes(contract.getPhone()))
.addColumn(Bytes.toBytes("info"), Bytes.toBytes("shuxing"), Bytes.toBytes(contract.getShuxing()))
.addColumn(Bytes.toBytes("info"), Bytes.toBytes("introduce"), Bytes.toBytes(contract.getIntroduce()))
.addColumn(Bytes.toBytes("info"), Bytes.toBytes("needName"), Bytes.toBytes(contract.getNeedName()))
.addColumn(Bytes.toBytes("info"), Bytes.toBytes("needIntroduce"), Bytes.toBytes(contract.getNeedIntroduce()))
.addColumn(Bytes.toBytes("info"), Bytes.toBytes("money"), Bytes.toBytes(contract.getMoney()))
.addColumn(Bytes.toBytes("info"), Bytes.toBytes("plan"), Bytes.toBytes(contract.getPlan()))
.addColumn(Bytes.toBytes("info"), Bytes.toBytes("khl"), Bytes.toBytes(contract.getKhl()));

table.put(put);

table.close();
} catch (IOException e) {
e.printStackTrace();
}
}

public List<Contract> scanRows() {
List<Contract> contractList = new ArrayList<Contract>();
try {
Table table = conn.getTable(TableName.valueOf("test1", "Contract"));

//创建scan
Scan scan = new Scan();

ResultScanner scanner = table.getScanner(scan);

Iterator<Result> iterator = scanner.iterator();
while (iterator.hasNext()){
Result result = iterator.next();
String rowkey = Bytes.toString(result.getRow());
Cell cname = result.getColumnLatestCell(Bytes.toBytes("info"),Bytes.toBytes("name"));
Cell caddress = result.getColumnLatestCell(Bytes.toBytes("info"),Bytes.toBytes("address"));
Cell cplace = result.getColumnLatestCell(Bytes.toBytes("info"),Bytes.toBytes("place"));
Cell cemail = result.getColumnLatestCell(Bytes.toBytes("info"),Bytes.toBytes("email"));
Cell cfaren = result.getColumnLatestCell(Bytes.toBytes("info"),Bytes.toBytes("faren"));
Cell ccontacts = result.getColumnLatestCell(Bytes.toBytes("info"),Bytes.toBytes("contacts"));
Cell cphone = result.getColumnLatestCell(Bytes.toBytes("info"),Bytes.toBytes("phone"));
Cell cshuxing = result.getColumnLatestCell(Bytes.toBytes("info"),Bytes.toBytes("shuxing"));
Cell cintroduce = result.getColumnLatestCell(Bytes.toBytes("info"),Bytes.toBytes("introduce"));
Cell cneedName = result.getColumnLatestCell(Bytes.toBytes("info"),Bytes.toBytes("needName"));
Cell cneedIntroduce = result.getColumnLatestCell(Bytes.toBytes("info"),Bytes.toBytes("needIntroduce"));
Cell cmoney = result.getColumnLatestCell(Bytes.toBytes("info"),Bytes.toBytes("money"));
Cell cplan = result.getColumnLatestCell(Bytes.toBytes("info"),Bytes.toBytes("plan"));
Cell ckhl = result.getColumnLatestCell(Bytes.toBytes("info"),Bytes.toBytes("khl"));

String name = Bytes.toString(CellUtil.cloneValue(cname));
String address = Bytes.toString(CellUtil.cloneValue(caddress));
String place = Bytes.toString(CellUtil.cloneValue(cplace));
String email = Bytes.toString(CellUtil.cloneValue(cemail));
String faren = Bytes.toString(CellUtil.cloneValue(cfaren));
String contacts = Bytes.toString(CellUtil.cloneValue(ccontacts));
String phone = Bytes.toString(CellUtil.cloneValue(cphone));
String shuxing = Bytes.toString(CellUtil.cloneValue(cshuxing));
String introduce = Bytes.toString(CellUtil.cloneValue(cintroduce));
String needName = Bytes.toString(CellUtil.cloneValue(cneedName));
String needIntroduce = Bytes.toString(CellUtil.cloneValue(cneedIntroduce));
String money = Bytes.toString(CellUtil.cloneValue(cmoney));
String plan = Bytes.toString(CellUtil.cloneValue(cplan));
String khl = Bytes.toString(CellUtil.cloneValue(ckhl));

Contract contract = new Contract(rowkey, name, address, place, email, faren, contacts, phone, shuxing, introduce, needName, needIntroduce, money, plan, khl);
contractList.add(contract);

}
table.close();
} catch (IOException e) {
e.printStackTrace();
}

return contractList;
}

public List<Contract> filterByOName(Contract contract) {

List<Contract> contractList = new ArrayList<Contract>();

try {
Table table = conn.getTable(TableName.valueOf("test1", "Contract"));
Scan scan = new Scan();

//添加过滤
FilterList filterList = new FilterList();
//创建过滤器
SingleColumnValueFilter valueFilter = new SingleColumnValueFilter(
//列族名
Bytes.toBytes("info"),
//列名
Bytes.toBytes("name"),
//比较关系
CompareOperator.EQUAL,
//值
Bytes.toBytes(contract.getName())
);
filterList.addFilter(valueFilter);
scan.setFilter(filterList);

ResultScanner scanner = table.getScanner(scan);

Iterator<Result> iterator = scanner.iterator();
while (iterator.hasNext()){
Result result = iterator.next();
String rowkey = Bytes.toString(result.getRow());
Cell cname = result.getColumnLatestCell(Bytes.toBytes("info"),Bytes.toBytes("name"));
Cell caddress = result.getColumnLatestCell(Bytes.toBytes("info"),Bytes.toBytes("address"));
Cell cplace = result.getColumnLatestCell(Bytes.toBytes("info"),Bytes.toBytes("place"));
Cell cemail = result.getColumnLatestCell(Bytes.toBytes("info"),Bytes.toBytes("email"));
Cell cfaren = result.getColumnLatestCell(Bytes.toBytes("info"),Bytes.toBytes("faren"));
Cell ccontacts = result.getColumnLatestCell(Bytes.toBytes("info"),Bytes.toBytes("contacts"));
Cell cphone = result.getColumnLatestCell(Bytes.toBytes("info"),Bytes.toBytes("phone"));
Cell cshuxing = result.getColumnLatestCell(Bytes.toBytes("info"),Bytes.toBytes("shuxing"));
Cell cintroduce = result.getColumnLatestCell(Bytes.toBytes("info"),Bytes.toBytes("introduce"));
Cell cneedName = result.getColumnLatestCell(Bytes.toBytes("info"),Bytes.toBytes("needName"));
Cell cneedIntroduce = result.getColumnLatestCell(Bytes.toBytes("info"),Bytes.toBytes("needIntroduce"));
Cell cmoney = result.getColumnLatestCell(Bytes.toBytes("info"),Bytes.toBytes("money"));
Cell cplan = result.getColumnLatestCell(Bytes.toBytes("info"),Bytes.toBytes("plan"));
Cell ckhl = result.getColumnLatestCell(Bytes.toBytes("info"),Bytes.toBytes("khl"));

String name = Bytes.toString(CellUtil.cloneValue(cname));
String address = Bytes.toString(CellUtil.cloneValue(caddress));
String place = Bytes.toString(CellUtil.cloneValue(cplace));
String email = Bytes.toString(CellUtil.cloneValue(cemail));
String faren = Bytes.toString(CellUtil.cloneValue(cfaren));
String contacts = Bytes.toString(CellUtil.cloneValue(ccontacts));
String phone = Bytes.toString(CellUtil.cloneValue(cphone));
String shuxing = Bytes.toString(CellUtil.cloneValue(cshuxing));
String introduce = Bytes.toString(CellUtil.cloneValue(cintroduce));
String needName = Bytes.toString(CellUtil.cloneValue(cneedName));
String needIntroduce = Bytes.toString(CellUtil.cloneValue(cneedIntroduce));
String money = Bytes.toString(CellUtil.cloneValue(cmoney));
String plan = Bytes.toString(CellUtil.cloneValue(cplan));
String khl = Bytes.toString(CellUtil.cloneValue(ckhl));

Contract contract1 = new Contract(rowkey, name, address, place, email, faren, contacts, phone, shuxing, introduce, needName, needIntroduce, money, plan, khl);
contractList.add(contract1);

}
table.close();

} catch (IOException e) {
e.printStackTrace();
}

return contractList;
}

}

HBase对表增查操作 API的更多相关文章

  1. HBase数据库增删改查常用命令操作

    最近测试用到了Hbase数据库,新建一个学生表,对表进行增删改查操作,把常用命令贴出来分享给大家~ 官方API:https://hbase.apache.org/book.html#quickstar ...

  2. JavaWeb_(Mybatis框架)使用Mybatis对表进行增、删、改、查操作_二

    系列博文: JavaWeb_(Mybatis框架)JDBC操作数据库和Mybatis框架操作数据库区别_一 传送门 JavaWeb_(Mybatis框架)使用Mybatis对表进行增.删.改.查操作_ ...

  3. 05_Elasticsearch 单模式下API的增删改查操作

    05_Elasticsearch 单模式下API的增删改查操作 安装marvel 插件: zjtest7-redis:/usr/local/elasticsearch-2.3.4# bin/plugi ...

  4. Elasticsearch 单模式下API的增删改查操作

    <pre name="code" class="html">Elasticsearch 单模式下API的增删改查操作 http://192.168. ...

  5. Elasticsearch学习系列之单模式下API的增删改查操作

    这里我们通过Elasticsearch的marvel插件实现单模式下API的增删改查操作 索引的初始化操作 创建索引之前可以对索引进行初始化操作,比如先指定shard数量以及replicas的数量 代 ...

  6. 【极力分享】[C#/.NET]Entity Framework(EF) Code First 多对多关系的实体增,删,改,查操作全程详细示例【转载自https://segmentfault.com/a/1190000004152660】

      [C#/.NET]Entity Framework(EF) Code First 多对多关系的实体增,删,改,查操作全程详细示例 本文我们来学习一下在Entity Framework中使用Cont ...

  7. (转)SQLite数据库增删改查操作

    原文:http://www.cnblogs.com/linjiqin/archive/2011/05/26/2059182.html SQLite数据库增删改查操作 一.使用嵌入式关系型SQLite数 ...

  8. [C#/.NET]Entity Framework(EF) Code First 多对多关系的实体增,删,改,查操作全程详细示例

    本文我们来学习一下在Entity Framework中使用Context删除多对多关系的实体是如何来实现的.我们将以一个具体的控制台小实例来了解和学习整个实现Entity Framework 多对多关 ...

  9. 分布式搜索Elasticsearch增、删、改、查操作深入详解

    引言: 对于刚接触ES的童鞋,经常搞不明白ES的各个概念的含义.尤其对“索引”二字更是与关系型数据库混淆的不行.本文通过对比关系型数据库,将ES中常见的增.删.改.查操作进行图文呈现.能加深你对ES的 ...

  10. JDBC连接数据库及增删改查操作

    什么是JDBC?Java语言访问数据库的一种规范,是一套APIJDBC (Java Database Connectivity) API,即Java数据库编程接口,是一组标准的Java语言中的接口和类 ...

随机推荐

  1. 利用ICSharpCode.SharpZipLib.dll解析 出错:“Wrong Local header signature: 0xFF8”

    分析原因 利用ICSharpCode.SharpZipLib.dll解析APK时,进入APK的AndroidXml获取时出现报错 出错代码 using (ICSharpCode.SharpZipLib ...

  2. Apache Hudi 流转批 场景实践

    背景 在某些业务场景下,我们需要一个标志来衡量hudi数据写入的进度,比如:Flink 实时向 Hudi 表写入数据,然后使用这个 Hudi 表来支持批量计算并通过一个 flag 来评估它的分区数据是 ...

  3. vue3.0+echart可视化

    vue3.0 + echart可视化 案例1: 案例代码 <template> <div ref="test" style="width:800px;h ...

  4. 搜索EE场景排序链路升级

    作者:京东零售 吕豪 背景 EE(Explore & Exploit)模块是搜索系统中改善生态.探索商品的重要链路,其目标是缓解数据马太效应导致模型对商品排序丰富性.探索性不足,带来的系统非最 ...

  5. Tomcat修改端口号问题

    今日面试问到如何修改Tomcat的问题 懵了 1.第一种就是我们常用的编辑器中 如:Idea中 一键式修改端口号(我只知道这个) 在下面的图 Http port后处修改即可,默认为8080端口 2.第 ...

  6. Java流程控制:用户交互Scanner、选择结构

    Java流程控制:用户交互Scanner.选择结构 用户交互Scanner Scanner类用于获取用户的输入 基本语法: Scanner s = new Scanner(System.in);s.c ...

  7. IP 地址分类及子网划分

    IP 地址分类 在现实生活中,一个市区有许多的区,区下面又有很多的街道,街道下面又有很多的小区,A 市区.B 市区就是一个范围,每一个范围都有不同的居民数量.类比到计算机网络,A 类地址可以容纳256 ...

  8. 一些常用计算机快捷键和dos命令

    1.window常用快捷键 ctrl V 粘贴 ctrl C 复制 ctrl A 全选 ctrl X 剪切 ctrl Z 撤销 ctrl S 保存 ALT F4 关闭窗口 shirt delete 永 ...

  9. redis-centOS系统的环境安装

    近期要简单汇总一下Redis常用的方法,依赖环境配置,在网上看到一篇比较好的Redis环境搭建博客,分享给大家.因新版本Redis已不支持windowns,环境安装以centOS系统为主. 参考博客地 ...

  10. 基于GPU 显卡在k8s 集群上实现hpa 功能

    前言 Kubernetes 支持HPA模块进行容器伸缩,默认支持CPU和内存等指标.原生的HPA基于Heapster,不支持GPU指标的伸缩,但是支持通过CustomMetrics的方式进行HPA指标 ...