3、练习常用的HBase Shell命令+HBase 常用的Java API 及应用实例

news/2024/10/4 1:27:13/

目录

  • (一)练习常用的HBase Shell命令
    • 1、启动HBase
    • 2、练习shell命令
      • create scan list describe alter
      • put
      • get
      • delete
      • drop
    • 关于NoSQL数据库中的列族和列
    • 3、关闭hbase服务
  • (二)HBase 常用的Java API 及应用实例
    • 1、启动hbase服务
    • 2、启动eclipse
    • 3、新建java project
      • 导入jar包
      • 创建类文件
      • 常用Java API:
      • 打开hbase shell
      • 退出hbase shell ——exit
    • 4、关闭 hbase

(一)练习常用的HBase Shell命令

1、启动HBase

先启动HDFS 再启动HBase
在这里插入图片描述
进入shell交互式执行环境
在这里插入图片描述

2、练习shell命令

在这里插入图片描述

create scan list describe alter

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

put

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

get

在这里插入图片描述

delete

在这里插入图片描述

在这里插入图片描述

drop

删除表前要disable它
在这里插入图片描述

关于NoSQL数据库中的列族和列

这些数据库允许你以非常灵活的方式存储和检索数据
在这里插入图片描述

在这里插入图片描述

hbase_35">3、关闭hbase服务

在这里插入图片描述

(二)HBase 常用的Java API 及应用实例

hbase_39">1、启动hbase服务

在这里插入图片描述

2、启动eclipse

在这里插入图片描述

java_project_43">3、新建java project

导入jar包

在这里插入图片描述
导入/usr/local/hbase/lib中的所有jar包
再导入/usr/local/hbase/lib/client-facing-thirdparty中的所有jar 包
在这里插入图片描述

创建类文件

在这里插入图片描述

常用Java API:

在这里插入图片描述

java">import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.*;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;
import java.io.IOException;public class ExampleForHBase {public static Configuration configuration;public static Connection connection;public static Admin admin;public static void main(String[] args) throws IOException {init();createTable("student", new String[]{"score"});insertData("student", "zhangsan", "score", "English", "69");insertData("student", "zhangsan", "score", "Math", "86");insertData("student", "zhangsan", "score", "Computer", "77");getData("student", "zhangsan", "score", "English");close();}public static void init() {configuration = HBaseConfiguration.create();configuration.set("hbase.rootdir", "hdfs://localhost:9000/hbase");try {connection = ConnectionFactory.createConnection(configuration);admin = connection.getAdmin();} catch (IOException e) {e.printStackTrace();}}public static void close() {try {if (admin != null) {admin.close();}if (connection != null) {connection.close();}} catch (IOException e) {e.printStackTrace();}}public static void createTable(String myTableName, String[] colFamily) throws IOException {TableName tableName = TableName.valueOf(myTableName);if (admin.tableExists(tableName)) {System.out.println("table is exists!");} else {TableDescriptorBuilder tableDescriptor = TableDescriptorBuilder.newBuilder(tableName);for (String str : colFamily) {ColumnFamilyDescriptor family = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(str)).build();tableDescriptor.setColumnFamily(family);}admin.createTable(tableDescriptor.build());}}public static void insertData(String tableName, String rowKey, String colFamily, String col, String val) throws IOException {Table table = connection.getTable(TableName.valueOf(tableName));Put put = new Put(rowKey.getBytes());put.addColumn(Bytes.toBytes(colFamily), Bytes.toBytes(col), Bytes.toBytes(val));table.put(put);table.close();}public static void getData(String tableName, String rowKey, String colFamily, String col) throws IOException {Table table = connection.getTable(TableName.valueOf(tableName));Get get = new Get(rowKey.getBytes());get.addColumn(Bytes.toBytes(colFamily), Bytes.toBytes(col));Result result = table.get(get);System.out.println(new String(result.getValue(Bytes.toBytes(colFamily), Bytes.toBytes(col))));table.close();}
}

run——>run as application

hbase_shell_134">打开hbase shell

list scan
在这里插入图片描述
在这里插入图片描述

hbase_shell_exit_138">退出hbase shell ——exit

hbase_139">4、关闭 hbase


http://www.ppmy.cn/news/1534200.html

相关文章

ARM V8 A32常用指令集

文章目录 1. 算术指令1.1 加法命令ADD\ADDS1.2 带进位加法命令ADC\ADCS1.3减法命令SUB\SUBC1.4带借位减法命令SBC\SBCS 2.逻辑运算指令2.1逻辑与指令AND、ANDS2.2位清零指令BIC2.3逻辑或指令ORR\ORRS2.4逻辑异或指令2.5 逻辑左移LSL2.6逻辑右移LSR 3.比较指令3.1直接比较指令CM…

华为仓颉语言入门(7):深入理解 do-while 循环及其应用

解锁Python编程的无限可能:《奇妙的Python》带你漫游代码世界 用法说明 do-while 表达式是一种控制循环的结构,它允许代码在每次循环之后进行条件判断。在这个表达式中,无论条件一开始是否满足,代码块都会被至少执行一次。 语法…

漫谈前端:2025年框架是该选vue还是react?

相信很多前端小伙伴都有过纠结的时候,开始一个项目的时候是该选vue还是react。很多情况下,都是根据团队现有框架延续,或者是自身数量度。渐渐的公司组件和规范全基于某一种框架,虽然很爽但Allin难掉头。本文就浅浅的比较下vue和re…

Spring Redis 使用总结

1.简介 Spring中常用Redis做数据库的缓存,第一次查询走数据库并缓存到redis,第二次查询由redis直接返回数据。 2.安装Redis mac安装: brew install redislinux安装: sudo apt-get install lsb-release curl gpg curl -fsSL …

【CSS】兼容处理

兼容前缀兼容查询 由于不同浏览器对CSS标准的支持程度不同,可能会导致在不同浏览器中出现样式差异。为了解决这个问题,需要采取一些措施来提高CSS的兼容性 兼容前缀 兼容前缀针对的浏览器-webkit-WebKit 内核浏览器,如:Safari 、…

#git 问题failed to resolve head as a valid ref

问题如下: 解决方法: 1、运行 git fsck --full 可以查看具体error信息,一般都是head索引问题 2、.git\refs\heads\xxx(当前分支)txt编辑器打开显示乱码,而不是hash编码 3、在.git\logs\refs\heads\xxx&a…

【代码随想录Day29】贪心算法Part03

134. 加油站 题目链接/文章讲解:代码随想录 视频讲解:贪心算法,得这么加油才能跑完全程!LeetCode :134.加油站_哔哩哔哩_bilibili class Solution {public int canCompleteCircuit(int[] gas, int[] cost) {// 创建一…

基于深度学习的不遗忘训练

基于深度学习的不遗忘训练(也称为抗遗忘训练或持久性学习)是针对模型在学习新任务时可能会忘记已学习内容的一种解决方案。该方法旨在使深度学习模型在不断接收新信息的同时,保持对旧知识的记忆。以下是这一领域的主要内容和方法:…