8 Hbase get方式获取数据
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方式获取数据的更多相关文章
- DataReader方式 获取数据的操作
一.使用DataReader读取为对象List /// <summary> /// 获得数据列表List<>,DataReader 使用参数的 /// </summary ...
- 关于 ThinkPHP5 使用 getBy 字段名方式获取数据
关于 ThinkPHP5 使用 getBy 字段名方式获取数据 有小伙半说怎么全文搜索都没有搜索到 getByName 之类的函数. 其实是在这里.
- ie浏览器下get方式获取数据无效问题
在ie浏览器用get方式获取数据时因为发送得到参数地址都是一样的,所以浏览器会优先从缓存获取数据,而不去服务器请求数据,post由于参数不同所以不会影响. 解决方法: 1. Internet选项-- ...
- Hbase之遍历获取数据
import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.hbase.HBaseConfiguration;import ...
- JAVA通过HTTP方式获取数据
测试获取免费天气数据接口:http://www.weather.com.cn/data/sk/101190408.html URL数据如下图: 代码部分: package https; import ...
- DataReader方式 获取数据
/// /// 得到一个对象实体 DataReader方式 /// /// /// 成功返回对象模型,失败返回null public DotNet.Model.Base_Department GetM ...
- 7 Hbase put方式插入数据
package com.hikvision.hbase.vertify.test; import org.apache.hadoop.conf.Configuration; import org.ap ...
- Qt.网络开发-通过http的get方式获取数据
Qt 是一个跨平台的 C++图形用户界面库,由挪威 TrollTech 公司于1995年底出品. 它是个跨平台的C++图形开发平台 我们在这章中可以学习简单的网络数据获取并显示的内容 本文基于Qt C ...
- Hibernate 以流的方式获取数据
hibernateQuery.setFetchSize(Integer.MIN_VALUE); results = hibernateQuery.scroll(ScrollMode.FORWARD_O ...
随机推荐
- mybatis入门,基本案例和xml讲解
mybatis入门 先举一个入门案例 1)创建一个mybatis-day01这么一个javaweb工程或java工程 2)导入mybatis和mysql/oracle的jar包到/WEB-INF/li ...
- Css3图片圆角,兼容所有浏览器
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- PHP根据概率产生随机数
假设 有四个选项:a 占 10%,b占20% ,C占30% , d 占 40% ,原理就是现获取随机数,然后找区间.当然了,选项的数量可以任意.目前默认是 总和是 100% .如果需要别的数,修改 随 ...
- R语言学习网站
一个不错的个人R语言博客网站 http://blog.fens.me/r-overview/
- DataTables自定义事件
$(document).ready(function() { var eventFired = function(type) { var n = $('#demo_info')[0]; n.inner ...
- Visual Studio express
之前一直没用过Visual Studio的express版本.在最近一段时间,使用VS2010和2012的破解版都有点问题.vs2010突然不能使用,需要重新安装,家里和单位两台电脑都如此.家里一台电 ...
- 最近写的页面,含有大量的ajax
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %><%@ taglib ur ...
- OC 冒泡排序 -- 核心代码
//冒泡 核心代码 for (int i = 0; i < array.count - 1; i++) { int a = [array[i] intValue]; for (int j = i ...
- Swift数据类型之整型和浮点型-备
Swift提供8.16.32.64位形式的有符号及无符号整数.这些整数类型遵循C语言的命名规约,我归纳了Swift中的整型: 整型示例: print("UInt8 range: \(UInt ...
- 《VIM-Adventures攻略》 LEVEL 1-3
此文已转至http://cn.abnerchou.me/2014/03/04/e40e2146/ 上期有人提到此游戏烂尾.其实没有啦,作者是位"贪财"的主,不付费不给玩剩下的章节. ...