In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
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");
}
}
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.