import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.*;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes; import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List; public class HBaseDemo { private static final String TABLE_NAME = "speech";
// private static final String CF_DEFAULT = "cf1";
// public static final byte[] QUALIFIER = "col1".getBytes();
// private static final byte[] ROWKEY = "999".getBytes(); public static void main(String[] args) {
Configuration config = HBaseConfiguration.create();
String zkAddress = "hb-bp17t03zm5o7p75s1-002.hbase.rds.aliyuncs.com:2181,hb-bp17t03zm5o7p75s1-003.hbase.rds.aliyuncs.com:2181,hb-bp17t03zm5o7p75s1-004.hbase.rds.aliyuncs.com:2181";
config.set(HConstants.ZOOKEEPER_QUORUM, zkAddress);
Connection connection = null; try {
connection = ConnectionFactory.createConnection(config);
//
// System.out.println("==========Get data==========");
Table table = connection.getTable(TableName.valueOf(TABLE_NAME));
try {
// // Get data
// Get get = new Get(ROWKEY);
// Result r = table.get(get);
// List<Cell> cs = r.listCells();
// for (Cell cell : cs){
// String rowKey = Bytes.toString(CellUtil.cloneRow(cell));
// //取行键
// long timestamp = cell.getTimestamp(); //取时间戳
// String family = Bytes.toString(CellUtil.cloneFamily(cell));
// //取到族列
// String qualifier =
// Bytes.toString(CellUtil.cloneQualifier(cell)); //取到修饰名
// String value = Bytes.toString(CellUtil.cloneValue(cell));
// //取到值
//
// System.out.println("===> rowKey : " + rowKey +", timestamp :
// "+timestamp + ", family : "+ family+", qualifier :
// "+qualifier+", value : " +value );
// } DateFormat df3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS"); // Scan data
System.out.println("==========Scan data Start==========");
System.out.println(df3.format(System.currentTimeMillis()));
String start = "rokid-12016-12-18 11:37:23010116004126";
String end = "rokid-12016-12-18 16:30:48010116000832";
Scan scan = new Scan(start.getBytes(),end.getBytes());
ResultScanner rs = table.getScanner(scan);
for (Result result : rs) {
List<Cell> cs1 = result.listCells();
for (Cell cell : cs1) {
String rowKey = Bytes.toString(CellUtil.cloneRow(cell));
long timestamp = cell.getTimestamp();
String family = Bytes.toString(CellUtil.cloneFamily(cell));
String qualifier = Bytes.toString(CellUtil.cloneQualifier(cell));
String value = Bytes.toString(CellUtil.cloneValue(cell));
//System.out.println(" ===> rowKey : " + rowKey + ", timestamp : " + timestamp + ", family : "
// + family + ", qualifier : " + qualifier + ", value : " + value);
}
}
System.out.println(df3.format(System.currentTimeMillis()));
System.out.println("==========Scan data Over==========");
config.setLong(HConstants.HBASE_REGIONSERVER_LEASE_PERIOD_KEY,3000000);
// Delete data
//System.out.println("==========Delete data Start==========");
//System.out.println(df3.format(System.currentTimeMillis())); //String start = "rokid-112017-01-18 03:34:590201011650000021";
//String end = "rokid-12016-02-08 00:24:46010116000035"; //Scan scan1 = new Scan(start.getBytes(),end.getBytes());
//ResultScanner rs1 = table.getScanner(scan1);
//List<Delete> ld = new ArrayList<Delete>();
//for (Result result : rs1) {
// ld.add(new Delete(result.getRow()));
// // List<Cell> cs1 = result.listCells();
// // for (Cell cell : cs1) {
// // table.delete(new Delete(CellUtil.cloneRow(cell)));
// // }
//}
//System.out.println(ld.size());
//System.out.println(df3.format(System.currentTimeMillis()));
//table.delete(ld);
//System.out.println(df3.format(System.currentTimeMillis()));
//System.out.println("==========Delete data Over==========");
} finally {
if (table != null)
table.close();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (connection != null) {
try {
connection.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}

文章参考:Hbase新版本JavaAPI编程实战及基本操作方法封装:

http://blog.csdn.net/tanggao1314/article/details/51408166

待续。。。

Hbase1.1.x Java版之批量查删操作的更多相关文章

  1. MongoDB安装、CURD增改查删操作、应用场景

    NoSQL(NoSQL = Not Only SQL ),意即"不仅仅是SQL".非关系型的数据存储 MongoDB 是一个基于分布式文件存储的数据库.由 C++ 语言编写.旨在为 ...

  2. Java典型应用彻查1000例:图形与网络游戏开发 PDF 扫描版[68M]

    <Java典型应用彻查1000例·图形与网络游戏开发>实例丰富,编排合理,可以让有初级Java基础的读者,从陌生到完全熟练地设计网络游戏,进而掌握3D立体绘图方法,适合作为Java网络游戏 ...

  3. PetaPojo —— JAVA版的PetaPoco

    背景 由于工作的一些原因,需要从C#转成JAVA.之前PetaPoco用得真是非常舒服,在学习JAVA的过程中熟悉了一下JAVA的数据组件: MyBatis 非常流行,代码生成也很成熟,性能也很好.但 ...

  4. Java API 快速速查宝典

    Java API 快速速查宝典 作者:明日科技,陈丹丹,李银龙,王国辉 著 出版社:人民邮电出版社 出版时间:2012年5月 Java编程的最基本要素是方法.属性和事件,掌握这些要素,就掌握了解决实际 ...

  5. 网页爬虫的设计与实现(Java版)

    网页爬虫的设计与实现(Java版)     最近为了练手而且对网页爬虫也挺感兴趣,决定自己写一个网页爬虫程序. 首先看看爬虫都应该有哪些功能. 内容来自(http://www.ibm.com/deve ...

  6. 解决Java版CKFinder无法显示缩略图问题

    这些天在写我的Java EE项目的时候用到了CKEditor和CKFinder,但是在用CKFinder的时候无法显示图片的缩略图,但是官网上的demo上却有缩略图,我一直以为是自己配置错误了,我把官 ...

  7. Elasticsearch 6.4基本操作 - Java版

    1. Elasticsearch Java API有四类client连接方式 TransportClient RestClient Jest Spring Data Elasticsearch 其中T ...

  8. 阿里云短信验证解决方案(java版)(redis存储)

    最近搞了一个互联网项目的注册,需要写一个手机号验证(由于之前没有轮子,只能自己摸索了); 1:基本思路: 1>购买了阿里云短信服务->下载阿里云短信发送demo(java版); 2> ...

  9. Java连接MySQL数据库及简单的增删查改操作

    主要摘自 https://www.cnblogs.com/town123/p/8336244.html https://www.runoob.com/java/java-mysql-connect.h ...

随机推荐

  1. visudo精确用户赋权(sudo)

    原文BLOG:http://iminmin.blog.51cto.com/689308/455992 sudo" 是Unix/Linux平台上的一个非常有用的工具,允许为非根用户赋予一些合理 ...

  2. SQL Server 2012 “阻止保存要求又一次创建表”的更改问题的设置方法

    我们在用SQL Server 2012 建完表后,插入或改动随意列时,提示:当用户在在SQL Server 2012企业管理器中更改表结构时.必需要先删除原来的表.然后又一次创建新表,才干完毕表的更改 ...

  3. 优化后队列的实现(C语言实现)

    上一篇中的队列的定义与实现(C语言实现) 中.不管是顺序队列还是链式队列,在尾加和删除头部的操作时.总有一个时间复杂度让人不惬意. 比方在顺序队列中,删除头部的操作后,总要将后面全部的结点都向前移动一 ...

  4. [Done]Spring @Pointcut 切点调用不到(SpringAOP嵌套方法不起作用) 注意事项

    今天在开发过程中,遇到一个问题卡了很久,测试代码如下: package spring.pointcut; import org.aspectj.lang.ProceedingJoinPoint; im ...

  5. java IO流之文件切割两例(含Properties 用法)

    package cn.itcast.io.p1.splitfile; import java.io.File;import java.io.FileInputStream;import java.io ...

  6. bash: fork: Resource temporarily unavailable

    Last login: Wed Jul 26 09:19:11 2017 from ... -bash: fork: Resource temporarily unavailable -bash-3. ...

  7. PHP基于Sphinx+Swcs中文分词的全文的检索

    简介 Sphinx是开源的搜索引擎,它支持英文的全文检索.所以如果单独搭建Sphinx,你就已经可以使用全文索引了 但是有些时候我们还要进行中文分词所有scws就出现了,我们也可以使用Coreseek ...

  8. SpringBoot自定义HttpMessageConverter

    Spring就是一个大大的插线板,上面插着各种各样的Bean. SpringBoot大大简化了Spring的配置,将原来放在XML中的配置大量的在代码中使用注解实现.这么做有利有弊,总体上利大于弊. ...

  9. C#:小写金额转换为大写

    #region 小写金额转换为大写 public static string CurrToChnNum(double Currnum) { string sResult = ""; ...

  10. map+pair Bayan 2015 Contest Warm Up D题

    D. CGCDSSQ time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...