实验要求:

根据上面给出的学生表Student的信息,执行如下操作:

  • 用Hbase Shell命令创建学生表Student;
  create 'student','name', 'score'
put 'student','01','name:name','zhangsan'
put 'student','01','score:English','69'
put 'student','01','score:Math','86'
put 'student','01','score:Computer,'77'
put 'student','02','name:name','lisi'
put 'student','02','score:English','55'
put 'student','02','score:Math','100'
put 'student','02','score:Computer','88'

  • 用scan命令浏览Student表的相关信息;
scan 'student'

  • 查询zhangsan的Computer成绩;\
get 'student','01','score:Computer'

  • 修改lisi的Math成绩,改为95;
put 'student' ,'02','score:Math','95'

核心代码:

//5.插入数据
public static void putData(String tableName, String rowKey,
String columnFamily, String
column, String value) throws IOException{
//获取表对象
Table table=connection.getTable(TableName.valueOf(tableName));
//创建put对象
Put put=new Put(Bytes.toBytes(rowKey));
//给put对象赋值
put.addColumn(Bytes.toBytes(columnFamily),Bytes.toBytes(column),Bytes.toBytes(value));
put.addColumn(Bytes.toBytes(columnFamily),Bytes.toBytes(column),Bytes.toBytes(value));
put.addColumn(Bytes.toBytes(columnFamily),Bytes.toBytes(column),Bytes.toBytes(value));
put.addColumn(Bytes.toBytes(columnFamily),Bytes.toBytes(column),Bytes.toBytes(value));
//添加数据
table.put(put);
//关闭连接
table.close();
} public static void main(String[] args) throws IOException {
//5.插入数据
putData("student","03","name","name","scofield");
putData("student","03","score","English","45");
putData("student","03","score","Math","89");
putData("student","03","score","Computer","100");
//关闭资源
close();
}
}

  • 获取scofield的English成绩信息。
public static void getData(String tableName,String rowKey,String columnFamily,String column) throws IOException{
//获取对象
Table table=connection.getTable(TableName.valueOf(tableName));
//创建GET对象
Get get=new Get(Bytes.toBytes(rowKey));
//指定获取的列族
get.addFamily(Bytes.toBytes(columnFamily));
//指定列族和列
get.addColumn(Bytes.toBytes(columnFamily),Bytes.toBytes(column));
//获取数据
Result result=table.get(get);
//解析result
for (Cell cell : result.rawCells()) {
//打印数据
System.out.println("columnFamily:"+Bytes.toString(CellUtil.cloneFamily(cell))+
",column:"+Bytes.toString(CellUtil.cloneQualifier(cell))+
",value:"+Bytes.toString(CellUtil.cloneValue(cell)));
}
//关闭表连接
table.close();
}
public static void main(String[] args) throws IOException {
//获取数据
//获取单行数据
getData("student","03","score","English");
//关闭资源
close();
}
}

HBase数据库基础操作的更多相关文章

  1. Mysql数据库基础操作

    Mysql数据库基础操作 在mysql数据库中开启使用tab键补全功能 1)修改主配置文件/etc/mysql/my.cnf(mysql和mariadb目录有些不同) vim /etc/mysql/m ...

  2. C# IV: 数据库基础操作2

    需上一篇C# III:数据库基础操作 另外一个经常碰到的数据库操作是,单次执行多个SQL语句,譬如,一次性插入多条数据. 方法一,拼凑长SQL语句 拼凑长SQL语句实际上是String的操作.如下示例 ...

  3. MySQL数据库----基础操作

    一.知识储备 数据库服务器:一台计算机(对内存要求比较高) 数据库管理系统:如mysql,是一个软件 数据库:oldboy_stu,相当于文件夹 表:student,scholl,class_list ...

  4. MySQL关系型数据库基础操作

    MySQL基础 一.MySQL常用数据类型 1.常用数值类型(INT,DOUBLE,FLOAT) ① int 或者 integer 类型: 大小(字节):4字节: 范围: (有符号: -2147483 ...

  5. MySQL数据库基础操作语句

    SQL语言主要用于存取数据.查询数据.更新数据和管理关系数据库系统,分为3种类型: 1.DDL语句 数据库定义语言: 数据库.表.视图.索引.存储过程,例如CREATE DROP ALTER 2.DM ...

  6. mysql 数据库基础操作

    一 知识储备 MySQL数据库基本操作知识储备 数据库服务器:一台计算机(对内存要求比较高) 数据库管理系统:如mysql,是一个软件 数据库:oldboy_stu,相当于文件夹 表:student, ...

  7. MongoDB数据库基础操作

    前面的话 为了保存网站的用户数据和业务数据,通常需要一个数据库.MongoDB和Node.js特别般配,因为Mongodb是基于文档的非关系型数据库,文档是按BSON(JSON的轻量化二进制格式)存储 ...

  8. python---基础知识回顾(八)数据库基础操作(sqlite和mysql)

    一:sqlite操作 SQLite是一种嵌入式数据库,它的数据库就是一个文件.由于SQLite本身是C写的,而且体积很小,所以,经常被集成到各种应用程序中,甚至在iOS和Android的App中都可以 ...

  9. 数据库基础操作-part2

    单表和多表查询 单表查询 记录详细操作: 增 insert into t1(字段1, 字段2, 字段3) values (值1, 值2, 值3), (值1, 值2, 值3), (值1, 值2, 值3) ...

随机推荐

  1. Linux 0.11源码阅读笔记-中断过程

    Linux 0.11源码阅读笔记-中断过程 是什么中断 中断发生时,计算机会停止当前运行的程序,转而执行中断处理程序,然后再返回原被中断的程序继续运行.中断包括硬件中断和软件中断,硬中断是由外设自动产 ...

  2. python-人物风云榜(实现排名)

    Description 又到了云之国一年一度的任务风云榜更新的大日子了.给出每个人风云力数值,需要你给出每个人的排名.注意,排名存在并列的情况. Input 一共有 22 行.第一行一个整数 n ,表 ...

  3. java中downcast向下转型到底有什么用

    What is the point of downcast? 当一个方法只有子类才有,马克-to-win:不是说基类和子类都有,开始时又是基类指针指向派生类,这时就需要downcast, see th ...

  4. Android点击按钮退出程序并提醒

    效果展示: MainActivity.java import androidx.appcompat.app.AppCompatActivity; import android.app.AlertDia ...

  5. uniapp热更新和整包升级

    一. uniapp热更新  (热更新官方文档) 很多人在开发uniapp的时候, 发现热更新失效问题(或者热更新没有更新manifest里的新增模块,SDK,原生插件包括云插件), 其实uniapp官 ...

  6. Vue快速入门(一)

    目录 Vue快速入门(一) 介绍 Vue.js 是什么 M-V-VM思想 安装 CDN引入 下载到本地 快速使用 双向数据绑定测试 模板语法 插值语法 指令 文本指令 v-html:让HTML渲染成页 ...

  7. Web安全中的常见Session攻击(预测+劫持+固定)

    攻击者至少可以通过以下三种方式来获取一个有效的session标识符: 1.预测 2.捕获(劫持) 3.固定 一.会话预测 预测这种方式,也就是攻击者需要猜测出系统中使用的有效的session标识符(P ...

  8. 解决windows下WslRegisterDistribution failed with error: 0x80070050的问题

    最近升级了老电脑的windows10的系统,发现wsl2里面安装的ubuntu20.04不能在windows terminal正常启动了(我之前是把ubuntu20.04作为默认启动终端的.) 涉及报 ...

  9. Fauce:Fast and Accurate Deep Ensembles with Uncertainty for Cardinality Estimation 论文解读(VLDB 2021)

    Fauce:Fast and Accurate Deep Ensembles with Uncertainty for Cardinality Estimation 论文解读(VLDB 2021) 本 ...

  10. Exception in thread "main" java.awt.AWTError: Assistive Technology not found: org.GNOME.Accessibilit

    系统环境 Ubuntu 20.04 focal 问题分析 该异常出现的原因,从谷歌上可以得到答案 one of the more common causes of this exception is ...