当前位置: 首页 > news >正文

java: 从HBase中读取数据

一、添加依赖:

        <dependency><groupId>org.apache.hadoop</groupId><artifactId>hadoop-client</artifactId><version>2.6.0</version></dependency><dependency><groupId>org.apache.hbase</groupId><artifactId>hbase-client</artifactId><version>2.4.2</version></dependency>

二、使用Scanner读取数据示例:

package cn.edu.tju;import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellScanner;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;public class TestHBaseRead {public static void main(String[] args) throws Exception {Configuration config = HBaseConfiguration.create();// create configuration//zookeeper 地址config.set("hbase.zookeeper.quorum","xxx.xxx.xxx.xxx");////zookeeper端口config.set("hbase.zookeeper.property.clientPort", "2181");////表名,必须提前在hbase中创建String tableName ="c1";//row keyString rowKey = "myKey2";//family,必须是hbase中有的familyString familyName = "fm2";//指定的某个column nameString specifiedColumnName = "by";Connection connection = ConnectionFactory.createConnection(config);Get g = new Get(rowKey.getBytes());g.addFamily(familyName.getBytes());try {Table table = connection.getTable(TableName.valueOf(tableName));Result result = table.get(g);CellScanner cellScanner =result.cellScanner();while (cellScanner.advance()){Cell cell = cellScanner.current();byte[] rowArray = cell.getRowArray(); //row key 字节数组byte[] familyArray = cell.getFamilyArray(); //列族 字节数组byte[] qualifierArray = cell.getQualifierArray();//列名 字节数据byte[] valueArray = cell.getValueArray();// 值 字节数组String columnName=new String(qualifierArray,cell.getQualifierOffset(),cell.getQualifierLength());String columnValue=new String(valueArray,cell.getValueOffset(),cell.getValueLength());if(specifiedColumnName.equals(columnName)){System.out.println(columnValue);}}}catch(Exception ex) {System.out.println(ex.getMessage());}}
}
http://www.lryc.cn/news/276786.html

相关文章:

  • Lumeical Script------Script Prompt 中的两种输出方式
  • 什么是OOM error
  • IO进程线程 day7
  • 扩展学习|数据融合助推商务智能与分析
  • Java项目:112SSM在线电影订票系统
  • Echarts——使用graphic组件在一个option内同时设置两个饼图的背景图
  • 编程笔记 html5cssjs 027 HTML输入属性(1/2)
  • 请求参数乱码问题
  • 【leetcode】力扣热门之反转链表【简单难度】
  • 【sgPasswordInput】自定义组件:带前端校验密码强度的密码输入框,能够提供密码强度颜色提示和文字提示
  • 1599 - Ideal Path (UVA)
  • 计算机网络(超级详细笔记)
  • 老杨说运维 | 年末大讲回顾:运维的尽头也是大模型吗?
  • Unity 利用UGUI之Scrollbar制作进度条
  • MySQL之导入、导出
  • 【unity小技巧】FPS游戏实现相机的偏移震动、武器射击后退和后坐力效果
  • MINCO+汽车
  • 大模型机器人发展史:从VoxPoser、RT2到斯坦福Mobile ALOHA、Google机器人
  • Ubunutu18.04 ROS melodic 无人机 XTDrone PX4 Vins-Fuison 运行配置
  • Linux 常见服务配置
  • Flutter基础
  • MySQL-数据库概述
  • HTML---JQurey的基本使用
  • 搜索docker镜像
  • 旋变检测AD2s1205手册学习笔记
  • 【温故而知新】JavaScript的防抖与节流
  • C++模板——(3)类模板
  • 深度学习中Epoch和Batch Size的关系
  • Python采集微博评论做词云图
  • 一文详解VScode 的远程开发