资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

java连接hbase-创新互联

package com.weshare.bigdata;

成都创新互联公司秉承实现全网价值营销的理念,以专业定制企业官网,网站设计、成都做网站,微信小程序,网页设计制作,手机网站开发,营销型网站建设帮助传统企业实现“互联网+”转型升级专业定制企业官网,公司注重人才、技术和管理,汇聚了一批优秀的互联网技术人才,对客户都以感恩的心态奉献自己的专业和所长。

import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;

public class hbaseLink {
static org.apache.hadoop.conf.Configuration configuration=null;
private org.apache.hadoop.hbase.client.Connection connection=null;
private Table table=null;

public void init() throws Exception{
    configuration=HBaseConfiguration.create();
    configuration.set("hbase.zookeeper.quorum", "服务器地址");
    configuration.set("hbase.zookeeper.property.clientPort", "服务器端口");// zookeeper端口
    connection=ConnectionFactory.createConnection(configuration);

// try {
// table = connection.getTable(TableName.valueOf("hbase表名"));
// ResultScanner rs = table.getScanner(new Scan());
// int num=0;
// for (Result r : rs) {
// Byte b= r.getRow(scan);
// System.out.println("获得到rowkey:" + new String(r.getRow()));
// num++;
//
// }System.out.print(num);
// }catch(Exception e){
// e.printStackTrace();
// }
}
public void queryall(String tableName) throws Exception{
table = connection.getTable(TableName.valueOf(tableName));
ResultScanner rs = table.getScanner(new Scan());
int num=0;
for (Result r : rs) {
//System.out.println("获得到rowkey:" + new String(r.getRow()));
num++;

 }
        System.out.print(num);
}
public void checkColName(String tableName,String rowkey,String exceptedColName) throws Exception{
    table = connection.getTable(TableName.valueOf(tableName));//建立hbase表链接
    Get scan = new Get(rowkey.getBytes());//获取rokey,将其转义成byte字节
    Result r=table.get(scan);//使用转义的rowkey查询表,将其查询结果返回给Result
    System.out.println("1");
    if(r.rawCells().equals("")||r.rawCells()==null||r.rawCells().length==0){
        System.out.println("3");
    }
    for (Cell keyValue : r.rawCells()) {
        System.out.println("2");
        String colName = Bytes.toString(keyValue.getQualifierArray(),keyValue.getQualifierOffset(),keyValue.getQualifierLength());
        if(!colName.equals(exceptedColName)){
            System.out.println("校验成功,不存在colName:"+exceptedColName+",实际colName:" + colName);
        }else if(colName.isEmpty()){
            System.out.println("校验成功,查询无colName");
        }else{
            System.out.println("校验失败");
        }
        System.out.println("12:"+keyValue.getFamilyLength());

    }

// Get coln=scan.addFamily(rowkey.getBytes());
// NavigableMap nm=scan.getFamilyMap(rowkey.getBytes());
// System.out.println(coln.toString());

}
public static void main(String[] args) throws Exception{
    hbaseLink hl=new hbaseLink();
    hl.init();
    hl.queryall("tablename");

// hl.checkColName("table","rowkey","column");
}
}

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


分享题目:java连接hbase-创新互联
文章分享:http://cdkjz.cn/article/gohcs.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220