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 ...
随机推荐
- ZOJ3558 How Many Sets III(公式题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud How Many Sets III Time Limit: 2 Seconds ...
- Spring4分别整合mongo2.X和3.0
1.pom文件添加: <dependency> <groupId>org.mongodb</groupId> <artifactId>mongo-jav ...
- web标准(复习)--4 纵向导航菜单及二级弹出菜单
今天我们开始学习纵向导航菜单及二级弹出菜单,包含以下内容和知识点: 纵向列表 标签的默认样式 css派生选择器 css选择器的分组 纵向二级列表 相对定位和绝对定位 一.纵向列表纵向列表或称为纵向导航 ...
- Json,Ajax(0516)
一.JSON简介: JSON(JavaScript Object Notation)是一种轻量级的数据交换语言,以文字为基础,且易于让人阅读,同时也方便了机器进行解析和生成.JSON简单说就是java ...
- Dede文章列表
文章列表标签的使用: {dede:arclist flag='h' typeid='' row='' col='' titlelen='' infolen='' imgwidth='' imgheig ...
- libevent入门(1)
libevent是什么 libevent 库实际上没有更换 select().poll() 或其他机制的基础.而是使用对于每个平台最高效的高性能解决方案在实现外加上一个包 ...
- Altium Designer (protel) 各版本“故障”随谈
Altium 的版本很多,每个版本都或多或少有些可容忍或可不容忍的问题,此贴只是希望各位能将遇到的问题写出来,只是希望 给还在使用 altium 的网友一些参考,也希望有些能被 altium 所接受@ ...
- Use OWIN to Self-Host ASP.NET Web API 2
Open Web Interface for .NET (OWIN)在Web服务器和Web应用程序之间建立一个抽象层.OWIN将网页应用程序从网页服务器分离出来,然后将应用程序托管于OWIN的程序 ...
- PowerShell文件系统(一)前言
PowerShell文件系统(一)前言 3 12 2月, 2014 在 Powershell tagged Powershell教程 / 别名 / 文件系统 by Mooser Lee PowerS ...
- Smarty 保留变量
{$smarty} 保留变量 可以通过PHP的保留变量 {$smarty}来访问一些环境变量. 下面是这些变量的列表: 页面请求变量 页面请求变量如$_GET, $_POST, $_COOKIE, $ ...