HBase对表增查操作 API
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的更多相关文章
- HBase数据库增删改查常用命令操作
最近测试用到了Hbase数据库,新建一个学生表,对表进行增删改查操作,把常用命令贴出来分享给大家~ 官方API:https://hbase.apache.org/book.html#quickstar ...
- JavaWeb_(Mybatis框架)使用Mybatis对表进行增、删、改、查操作_二
系列博文: JavaWeb_(Mybatis框架)JDBC操作数据库和Mybatis框架操作数据库区别_一 传送门 JavaWeb_(Mybatis框架)使用Mybatis对表进行增.删.改.查操作_ ...
- 05_Elasticsearch 单模式下API的增删改查操作
05_Elasticsearch 单模式下API的增删改查操作 安装marvel 插件: zjtest7-redis:/usr/local/elasticsearch-2.3.4# bin/plugi ...
- Elasticsearch 单模式下API的增删改查操作
<pre name="code" class="html">Elasticsearch 单模式下API的增删改查操作 http://192.168. ...
- Elasticsearch学习系列之单模式下API的增删改查操作
这里我们通过Elasticsearch的marvel插件实现单模式下API的增删改查操作 索引的初始化操作 创建索引之前可以对索引进行初始化操作,比如先指定shard数量以及replicas的数量 代 ...
- 【极力分享】[C#/.NET]Entity Framework(EF) Code First 多对多关系的实体增,删,改,查操作全程详细示例【转载自https://segmentfault.com/a/1190000004152660】
[C#/.NET]Entity Framework(EF) Code First 多对多关系的实体增,删,改,查操作全程详细示例 本文我们来学习一下在Entity Framework中使用Cont ...
- (转)SQLite数据库增删改查操作
原文:http://www.cnblogs.com/linjiqin/archive/2011/05/26/2059182.html SQLite数据库增删改查操作 一.使用嵌入式关系型SQLite数 ...
- [C#/.NET]Entity Framework(EF) Code First 多对多关系的实体增,删,改,查操作全程详细示例
本文我们来学习一下在Entity Framework中使用Context删除多对多关系的实体是如何来实现的.我们将以一个具体的控制台小实例来了解和学习整个实现Entity Framework 多对多关 ...
- 分布式搜索Elasticsearch增、删、改、查操作深入详解
引言: 对于刚接触ES的童鞋,经常搞不明白ES的各个概念的含义.尤其对“索引”二字更是与关系型数据库混淆的不行.本文通过对比关系型数据库,将ES中常见的增.删.改.查操作进行图文呈现.能加深你对ES的 ...
- JDBC连接数据库及增删改查操作
什么是JDBC?Java语言访问数据库的一种规范,是一套APIJDBC (Java Database Connectivity) API,即Java数据库编程接口,是一组标准的Java语言中的接口和类 ...
随机推荐
- 继承与多态 动手动脑3方法覆盖(override)”的要点
方法覆盖(override)"的要点 方法覆盖要求子类与父类的方法一模一样,否则就是方法重载(overload)! 在子类中,若要调用父类中被覆盖的方法,可以使用super关键字. 以下子类 ...
- 基于pytorch实现模型剪枝
一,剪枝分类 1.1,非结构化剪枝 1.2,结构化剪枝 1.3,本地与全局修剪 二,PyTorch 的剪枝 2.1,pytorch 剪枝工作原理 2.2,局部剪枝 2.2.1,局部非结构化剪枝 2.2 ...
- [EULAR文摘] 滑膜HIF-1a与类风湿关节炎的关节破坏
滑膜HIF-1a与类风湿关节炎的关节破坏 Wei XN, et al. EULAR 2015. Present ID: OP0070. 背景:低氧诱导因子(HIF)-1α是缺氧条件下细胞反应的一个关键 ...
- Vue学习笔记之计算属性、内容分发、自定义事件
1. 计算属性 计算属性的重点突出在属性两个字上(属性是名词),首先它是个属性其次这个属性有计算的能力(计算是动词),这里的计算就是个函数:简单点说,它就是一个能够将计算结果缓存起来的属性(将行为转化 ...
- 初始化安装后 Nacos 动态路由配置不生效
一.问题描述 1.每次初始化安装整套项目,包括安装 Nacos 和其他服务还有mysql,redis等其他中间件,安装后 Nacos 获取不到 nacos 路由信息(包括后续新写入动态路由配置)!只有 ...
- Python (进阶 第二部)
目录 函数 闭包 匿名函数 迭代器 高阶函数 推导式 递归函数 函数 函数的定义: 功能( 包括一部分代码,实现某种功能,达成某个目的) 函数的特点: 函数可以反复调用 ,提高代码的复用性,提高开 ...
- 编程基础与python介绍
思维导图 https://gitee.com/starry-tong/python-data/blob/pyimage/day02.png 1.计算机内部存储数据的原理 2.编程语言的发展史 3.py ...
- Markdown的学习方式
Markdown的学习 标题 二级标题表示 \# + 标题名字 若是三级标题以及更多级标题根据\#的个数表示多少级 字体 ### 粗体: **+ 名字 +** **Hello World** 斜体: ...
- 一些常用计算机快捷键和dos命令
1.window常用快捷键 ctrl V 粘贴 ctrl C 复制 ctrl A 全选 ctrl X 剪切 ctrl Z 撤销 ctrl S 保存 ALT F4 关闭窗口 shirt delete 永 ...
- Git上手教程
不说费话,直接上链接 廖雪峰老师的GIT教程