实验要求:

根据上面给出的学生表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. C++中初始化列表的使用(总结)

    原文链接 https://www.cnblogs.com/dishengAndziyu/p/10906081.html 参考链接:https://www.cnblogs.com/laiqun/p/57 ...

  2. android webview与jquery mobile相互通信

    最近做android项目中遇到要在webview中做与js交互相关的东东,涉及到js中调用android本地的方法,于是查了资料整理了一下android和js互相调用的过程.如下demo,demo的主 ...

  3. 干货,看微信小程序后台用户数据如何演变和递增

    这几天发现附近小程序又多了好几家,其中有普通小程序和门店小程序,把它们做一个对比,门店小程序更多的像一张名片,只有基本的企业名称.地址.营业时间.电话和门店照片,和普通小程序相比显得逊色许多.楼下的水 ...

  4. 【weex开发】weex官方源码

    公司目前使用版本:weex_sdk:0.10.0 介绍地址:https://bintray.com/alibabaweex/maven/weex_sdk/0.18.0 weex最新版本:weex_sd ...

  5. JavaScript实现按钮改变网页背景色

    运行效果: 源代码: 1 <!DOCTYPE html> 2 <html lang="zh"> 3 <head> 4 <meta char ...

  6. 引入css的方式

    ---恢复内容开始--- 引入css的样式及link和@import的区别 有3种引入方式 1.内部样式(写在标签内) 2.内联样式 3.外部样式(link @import) 区别: 1.本质区别:l ...

  7. SpringMVC快速使用——基于注解

    SpringMVC快速使用--基于注解 1.引入依赖 <!-- 定义Spring版本 --> <properties> <spring.verson>5.3.8&l ...

  8. 【Azure Developer】使用 CURL 获取 Key Vault 中 Secrets 中的值

    问题描述 在使用CURL通过REST API获取Azure Key Vaualt的Secrets值,提示Missing Token, 问如何来生成正确的Token呢? # curl 命令 curl - ...

  9. 技术分享 | SeleniumIDE用例录制

    1.录制回放方式的稳定性和可靠性有限 2.只支持 Firefox.Chrome 3.对于复杂的页面逻辑其处理能力有限 环境准备 Chrome 插件:https://chrome.google.com/ ...

  10. vue2响应式原理与vue3响应式原理对比

    VUE2.0 核心 对象:通过Object.defineProtytype()对对象的已有属性值的读取和修改进行劫持 数组:通过重写数组更新数组一系列更新元素的方法来实现元素的修改的劫持 Object ...