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 ...
随机推荐
- hdu5353
模拟,,, 每个人有一些糖果,每两个人之间只能给一个糖果,问最后是否能让所有人的糖果数量相同,只要确定一个糖果的流向其他的就能够确定. 马虎了,卡了好几天,心塞塞的... #include<io ...
- test在博客中嵌入实例代码
// 其实很简单,只要把css.div.js代码直接写在里面就可以了.通过查看源代码就能看得很清楚了. 要注意的一点就是:如果div里没有任何内容,则它会被(博客网)删除掉,所以即使没有内容, ...
- CSS/CSS3长度、时间、频率、角度单位大全
by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=1494 一.一笔带过的 ...
- ASP.NET MVC 4.0的Action Filter
有时候你想在调用action方法之前或者action方法之后处理一些逻辑,为了支持这个,ASP.NET MVC允许你自定义创建action过滤器.Action过滤器是自定义的Attributes,用来 ...
- PHP数组相加
+ 运算符把右边的数组元素(除去键值与左边的数组元素相同的那些元素)附加到左边的数组后面,但是重复的键值不会被覆盖 ,array_merge()此时会覆盖掉前面相同键名的值 如: $a=array(' ...
- iOS开发:UILabel无法响应点击事件的问题
UILabel 是默认关闭用户的交互的 即: _contentLabel.userInteractionEnabled = NO; 修改之后: _contentLabel.userInteractio ...
- m2eclipse插件安装
一.给Eclipse安装maven的插件 m2eclipse 1 打开eclipse 2 Help -->Eclipse MarketPlace,在打开的界面搜索框中输入maven查找m2ecl ...
- php 过滤html标签的函数
1:strip_tags(string,allow)用来过滤html标签,参数string必须,allow是指定允许哪些标签通过. 例如: <?php $info='<a href=&qu ...
- iptables 顺序
-A INPUT -s 115.236.6.6/32 -p udp -m udp --dport 111 -j ACCEPT -A INPUT -s 10.175.197.98/32 -p udp - ...
- vbox安装mac os x
http://zhiwei.li/text/2013/12/%E5%9C%A8virtualbox4-3-4%E4%B8%AD%E5%AE%89%E8%A3%85mavericks/ http://g ...