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. jquery(四:jquery的事件、Ajax)

    Jquery事件 jQuery注册事件 1.利用原生的js来为对象注册事件,后面的会把前面的覆盖 2.用jQuery的$()来为对象注册事件,后面不会把前面的覆盖 简单事件绑定-----click() ...

  2. Cesium源码之flyTo(一)

    1 /** 2 * Flies the camera from its current position to a new position. 3 * 4 * @param {Object} opti ...

  3. 题解 P4163 [SCOI2007]排列

    强烈谴责只有 125MB 的行为,然后我没删调试是个什么 SB... 闲话少说,切入正题-- 首先看到取余和数字是可以排列的,我们自然而然的想到了数位 dp,但是很显然这题不是的数位 dp 通常解决的 ...

  4. uWSGI 结合 nginx 配置动静分离

    uWSGI 结合 nginx 配置动静分离 目录 uWSGI 结合 nginx 配置动静分离 1 环境准备 2 初始配置文件 2.1 uwsgi 配置文件 2.2 Nginx配置文件 2.3 Djan ...

  5. select去除默认样式

    select { /*Chrome同Firefox与IE里面的右侧三角显示的样式不同*/ border: solid 1px #ddd; /*将默认的select选择框样式清除*/ appearanc ...

  6. PostgreSQL处理膨胀与事务回卷

    一.表膨胀查询与处理 1.创建扩展 create extension pgstattuple; 2.表膨胀查询 pgstattuple提供了pgstatetuple()和pgstatindex()两个 ...

  7. Dockerfile构建python项目

    一.步骤 1.镜像基础 2.复制代码 3.设置工作目录 4.把需要执行的shell命令编写成脚本文件 5.配置容器启动自动执行脚本,CMD在docker run时运行脚本 DockerFile 脚本 ...

  8. java struts2框架漏洞合集

    目录 struts2 s2-016 payload 数据包 返回结果 struts2 s2-016 参考:https://github.com/vulhub/vulhub/blob/master/st ...

  9. lg7335 [JRKSJ R1] 异或 题解

    本题的标签中含有trie,但是这道题可以不用trie做. 考虑列出本题的dp方程:设\(f_{k,i}\)表示前\(i\)个数选了\(k\)段的答案,\(s_i\)为数组的前缀异或和 当不选择第\(i ...

  10. emacs config on win10 for rust 1

    native win32 (setq package-archives '(("gnu" . "http://mirrors.ustc.edu.cn/elpa/gnu/& ...