网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

Java代码访问Hbase测试-创新互联

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();
}

}

创新互联-专业网站定制、快速模板网站建设、高性价比庆云网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式庆云网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖庆云地区。费用合理售后完善,十年实体公司更值得信赖。

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

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网页标题:Java代码访问Hbase测试-创新互联
文章转载:http://bjjierui.cn/article/coedge.html

其他资讯