Java代码访问Hbase测试
admin
2023-02-08 01:40:06
0

import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.Test;

public class Run {

static Configuration conf = null;

public static Configuration configuration;
static {
conf = HBaseConfiguration.create();
configuration = HBaseConfiguration.create();
configuration.set("hbase.zookeeper.property.clientPort", "2181");
configuration.set("hbase.zookeeper.quorum", "hd1,hd2,hd3,hd4");
configuration.set("hbase.master", "hd1:60000");
}


public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
try {
System.out.println("start");

go();
System.out.println("over");
}
catch (Exception e)
{
System.out.println(e.toString());
}
}

public Run() throws IOException {
super();

}

public static void go() throws IOException
{
for (int i1 = 0; i1 <= 3; i1++) {
for (int i2 = 0; i2 <= 3; i2++) {
for (int i3 = 0; i3 <= 3; i3++) {
for (int i4 = 0; i4 <= 3; i4++) {
System.out.println(Integer.toString(i1*1000+i2*100+i3*10+i4));
addData(i1, i2, i3, i4);
}
}
}
}
}

public static void addData(int i1, int i2, int i3, int i4) throws IOException {
String strTBName = "ttable0";
String strColFamily = "tuser";
String strColumn = "b";//列名
String strRowKey = "";//行号
String strValue = "1";//值

HTable table1 = new HTable(conf, strTBName);
strRowKey = Integer.toString(i1)+Integer.toString(i2)+Integer.toString(i3)+Integer.toString(i4);
Put put = new Put(Bytes.toBytes(strRowKey));// 设置行号,RowKey

put.add(Bytes.toBytes(strColFamily), Bytes.toBytes(strColumn),
Bytes.toBytes(strValue));

table1.put(put);

table1.close();
}


}

单纯这样写,别的问题没有,就是速度超级慢。损失的环节主要是建立连接和分配HTable的时候。 




相关内容

热门资讯

男子在采血站采血后口吐白沫、神... 7月23日,山西广播电视台《慧帮忙》栏目报道“我弟弟在霍州康宝生物科技采血站采血后口吐白沫、神志不清...
“安全先生”,不安全了 当地时间7月17日凌晨,以色列第25届议会以62票赞成、0票反对通过一项有关政党经费法的相关修正案,...
“AI科学家”,实验效率直接“... □ 本报记者 洪叶 徐春晖 窗明几净的空间里没有科研人员,取而代之的是一排充满科技感的自动化岛台,背...
云南一女子电脑屏内现“蚂蚁窝”... 大家平时清洁电脑显示屏吗? 你见过显示屏里进蚂蚁吗? 据媒体报道,云南临沧一名女子近期发现,自己使...
便携脑电采集新品发布,脑电信号... 一根发带将一个比硬币略大的采集设备贴在额头,就能实现脑电信号采集,脑机接口创新企业神舞科技7月22日...
工业和信息化部:依托标准牵引智... 日前,在北京举办的《人工智能 智能体互联》系列标准应用推进专题会上,工业和信息化部科技司副司长甘小斌...
原创 强... 进入下半年,子系品牌新一轮旗舰和中端性能机开始密集预热,近期更是有博主连续放出两条关键信息,分别指向...
“文学超界面”探索数字时代人文... 来源:新华网 当严肃文学的深厚内核遇见人工智能生成内容(AIGC)的影像创造力,会碰撞出怎样的火花...
以防长称已为应对伊朗局势做好“... △以色列国防部长卡茨(资料图)当地时间23日,据以色列方面消息,以色列国防部长卡茨当天表示,鉴于当前...
美参议院否决限制特朗普对伊战争... △美国国会(资料图)当地时间23日,美国参议院以49票对47票的表决结果,否决了旨在限制特朗普对伊朗...