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的时候。 




相关内容

热门资讯

终于了解“新老夫子拼三张.开挂... 家人们!今天小编来为大家解答新老夫子拼三张透视挂怎么安装这个问题咨询软件客服徽9752949的挂在哪...
今日重大发现“龙泰棋牌.究竟有... 您好:龙泰棋牌这款游戏可以开挂,确实是有挂的,需要了解加客服微信【9752949】很多玩家在这款游戏...
【第一消息】“乐友棋牌.可以开... 【第一消息】“乐友棋牌.可以开挂吗?”太坑了原来有挂您好,乐友棋牌这个游戏其实有挂的,确实是有挂的,...
终于明白“九九牌游十三水.究竟... 有 亲,根据资深记者爆料九九牌游十三水是可以开挂的,确实有挂(咨询软件无...
今日重大发现“天天福建麻将.辅... 网上科普关于“天天福建麻将有没有挂”话题很是火热,小编也是针对天天福建麻将作*弊开挂的方法以及开挂对...
【第一消息】“长虹大厅.怎么开... 有 亲,根据资深记者爆料长虹大厅是可以开挂的,确实有挂(咨询软件无需打开...
【第一消息】“POKER.有没... 您好:POKER这款游戏可以开挂,确实是有挂的,需要了解加客服微信【4282891】很多玩家在这款游...
终于了解“熊猫来了.到底有挂吗... 终于了解“熊猫来了.到底有挂吗?”原来真的有挂您好,熊猫来了这个游戏其实有挂的,确实是有挂的,需要了...
玩家攻略科普“摇钱树拼三张.有... 网上科普关于“摇钱树拼三张有没有挂”话题很是火热,小编也是针对摇钱树拼三张作*弊开挂的方法以及开挂对...
今日重大消息“冷酷牛牛.开挂器... 家人们!今天小编来为大家解答冷酷牛牛透视挂怎么安装这个问题咨询软件客服徽9752949的挂在哪里买很...