package com.hikvision.hbase.vertify.test;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import java.io.IOException;
import java.io.InterruptedIOException;
import java.io.UnsupportedEncodingException; /**
*/
public class HbaseGetTest {
public static final Logger LOGGER= LoggerFactory.getLogger(HbasePutTest.class);
public final static String HBASE_MASTER = "hbase.master";
public final static String HBASE_ZOOKEEPER_PORT = "hbase.zookeeper.property.clientPort";
public final static String HBASE_ZOOKEEPER_QUORUM = "hbase.zookeeper.quorum";
public static HTable htable;
public static void main(String[] args) {
String hbaseMaster="10.17.139.121:60010";
String zookeeperPort="";
String zookeeperQuorum="10.17.139.121";
String tableName="testHbaseHdfsFileCopy";
Configuration config= HBaseConfiguration.create();
config.set(HBASE_MASTER, hbaseMaster);
config.set(HBASE_ZOOKEEPER_PORT, zookeeperPort);
config.set(HBASE_ZOOKEEPER_QUORUM, zookeeperQuorum); try {
htable = new HTable(config, tableName);
} catch (IOException e) {
e.printStackTrace();
} if(null==htable){
LOGGER.error("htable is null");
System.exit(-);
}
int i=;
while(true){
String rowkey="";
if(i<) {
rowkey = ""+i;
}else if(i<){
rowkey = ""+i;
}
else if(i<){
rowkey = ""+i;
}
else if(i<){
rowkey = ""+i;
}
else if(i<){
rowkey = ""+i;
}
else if(i<){
rowkey = ""+i;
}
else if(i<){
rowkey = ""+i;
}
else if(i<){
rowkey = ""+i;
}
else if(i<){
rowkey = ""+i;
}
else if(i<){
rowkey = ""+i;
}else if(i<){
rowkey = ""+i;
}
String family="info";
String column=""+i;
Result result=getDataFromTable(rowkey,family,column);
try {
LOGGER.info(new String(result.getValue(Bytes.toBytes(family),Bytes.toBytes(column)),"utf-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
try {
Thread.sleep();
} catch (InterruptedException e) {
e.printStackTrace();
}
i++;
if(i==){
i=;
}
}
}
/**
* @Description:往表中插入数据
* @param rowkey
* @param ts
* @param family
* @param column
* @param value void:
*/
public static void putDataToTable(String rowkey, long ts, String family, String column, int value) {
Put put = new Put(Bytes.toBytes(rowkey), ts);
put.addColumn(Bytes.toBytes(family), Bytes.toBytes(column), Bytes.toBytes(value));
try {
htable.put(put);
} catch (RetriesExhaustedWithDetailsException e) {
e.printStackTrace();
} catch (InterruptedIOException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} /**
* @Description:往表中插入数据
* @param rowkey
* @param ts
* @param family
* @param column
* @param value void:
*/
public static void putDataToTable(String rowkey, long ts, String family, String column, String value) {
Put put = new Put(Bytes.toBytes(rowkey), ts);
put.add(Bytes.toBytes(family), Bytes.toBytes(column), Bytes.toBytes(value));
try {
htable.put(put);
} catch (RetriesExhaustedWithDetailsException e) {
e.printStackTrace();
} catch (InterruptedIOException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} /**
* @Description:从表中查询数据
* @param rowkey
* @param family
* @param column
* @return Result:
*/
public static Result getDataFromTable(String rowkey, String family, String column) {
Get get = new Get(Bytes.toBytes(rowkey));
get.addColumn(Bytes.toBytes(family), Bytes.toBytes(column));
Result dbresult = null;
try {
dbresult = htable.get(get);
} catch (IOException e) {
e.printStackTrace();
}
return dbresult;
} /**
* @Description:从表中查询数据
* @param rowkey
* @param family
* @param column
* @return Result:
*/
public static Result getDataFromTable(String rowkey, String family, String... column) {
Get get = new Get(Bytes.toBytes(rowkey));
for (String string : column) {
get.addColumn(Bytes.toBytes(family), Bytes.toBytes(string));
}
Result dbresult = null;
try {
dbresult = htable.get(get);
} catch (IOException e) {
e.printStackTrace();
}
return dbresult;
}
}

8 Hbase get方式获取数据的更多相关文章

  1. DataReader方式 获取数据的操作

    一.使用DataReader读取为对象List /// <summary> /// 获得数据列表List<>,DataReader 使用参数的 /// </summary ...

  2. 关于 ThinkPHP5 使用 getBy 字段名方式获取数据

    关于 ThinkPHP5 使用 getBy 字段名方式获取数据 有小伙半说怎么全文搜索都没有搜索到 getByName 之类的函数. 其实是在这里.

  3. ie浏览器下get方式获取数据无效问题

    在ie浏览器用get方式获取数据时因为发送得到参数地址都是一样的,所以浏览器会优先从缓存获取数据,而不去服务器请求数据,post由于参数不同所以不会影响. 解决方法: 1.  Internet选项-- ...

  4. Hbase之遍历获取数据

    import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.hbase.HBaseConfiguration;import ...

  5. JAVA通过HTTP方式获取数据

    测试获取免费天气数据接口:http://www.weather.com.cn/data/sk/101190408.html URL数据如下图: 代码部分: package https; import ...

  6. DataReader方式 获取数据

    /// /// 得到一个对象实体 DataReader方式 /// /// /// 成功返回对象模型,失败返回null public DotNet.Model.Base_Department GetM ...

  7. 7 Hbase put方式插入数据

    package com.hikvision.hbase.vertify.test; import org.apache.hadoop.conf.Configuration; import org.ap ...

  8. Qt.网络开发-通过http的get方式获取数据

    Qt 是一个跨平台的 C++图形用户界面库,由挪威 TrollTech 公司于1995年底出品. 它是个跨平台的C++图形开发平台 我们在这章中可以学习简单的网络数据获取并显示的内容 本文基于Qt C ...

  9. Hibernate 以流的方式获取数据

    hibernateQuery.setFetchSize(Integer.MIN_VALUE); results = hibernateQuery.scroll(ScrollMode.FORWARD_O ...

随机推荐

  1. HTML 学习网站

    http://www.w3school.com.cn/tiy/t.asp?f=html_intro

  2. 一个Hadoop难以查找的错误

    This script is Deprecated. Instead use start-dfs.sh and start-yarn.sh Starting namenodes on [Master1 ...

  3. 怎样使用pyinstaller打包

    安装好pyinstaller后 cd 到pyinstaller.py目录,在命令行输入:python pyinstaller.py 参数 主文件所在目录 如:python pyinstaller.py ...

  4. JS 闭包问题

    一.什么是闭包?“官方”的解释是:所谓“闭包”,指的是一个拥有许多变量和绑定了这些变量的环境的表达式(通常是一个函数),因而这些变量也是该表达式的一部分. 相信很少有人能直接看懂这句话,因为他描述的太 ...

  5. 最近写的页面,含有大量的ajax

    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %><%@ taglib ur ...

  6. GCD使用经验与技巧浅谈--备

    GCD(Grand Central Dispatch)可以说是Mac.iOS开发中的一大“利器”,本文就总结一些有关使用GCD的经验与技巧. dispatch_once_t必须是全局或static变量 ...

  7. 对CNN模块的分析

    对 CNN 模块的分析,该论文(Systematic evaluation of CNN advances on the ImageNet)已经做过了,里面的发现是非常有帮助的:   使用没有 bat ...

  8. 用root帐号切换其他帐号提示 su: warning: cannot change directory to /home/oracle: Permission denied

    用root帐号切换其他帐号提示: 出错原因: 基本上是根目录或者是/home/oracle目录权限的问题 解决办法: 更改根目录权限为755,并保证对应用户主目录的所属用户和所属组一致和用户名一致. ...

  9. codeforces Ilya and Matrix

    http://codeforces.com/contest/313/problem/C #include <cstdio> #include <cstring> #includ ...

  10. AMS1117典型电路

    AMS1117(3.3V.5V) 封装: 常见应用连接: 1.输入旁路电容Input Bypass Capacitor:A 10uF tantalum on the input is a suitab ...