hbase中创建表、插入数据,更新数据,删除数据的操作
发表于:2025-02-02 作者:千家信息网编辑
千家信息网最后更新 2025年02月02日,本篇内容介绍了"hbase中创建表、插入数据,更新数据,删除数据的操作"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读
千家信息网最后更新 2025年02月02日hbase中创建表、插入数据,更新数据,删除数据的操作
本篇内容介绍了"hbase中创建表、插入数据,更新数据,删除数据的操作"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
所需要的包有:
commons-codec-1.4.jar
commons-logging-1.1.1.jar
hadoop-0.20.2-core.jar
hbase-0.90.2.jar
log4j-1.2.16.jar
zookeeper-3.3.2.jar
背景:
假设有一个不知道是干什么表:)
表里需要存入人员和其相对应的部门信息
代码:
import java.util.ArrayList;import java.util.List;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.hbase.HBaseConfiguration;import org.apache.hadoop.hbase.HColumnDescriptor;import org.apache.hadoop.hbase.HTableDescriptor;import org.apache.hadoop.hbase.client.Delete;import org.apache.hadoop.hbase.client.HBaseAdmin;import org.apache.hadoop.hbase.client.HTable;import org.apache.hadoop.hbase.client.Put; public class HbaseAddEdtDel { public static Configuration configuration=null; static { configuration = HBaseConfiguration.create(); configuration.set("hbase.master", "192.168.0.201:60000"); configuration.set("hbase.zookeeper.quorum","192.168.0.201,192.168.0.202,192.168.0.203"); configuration.set("hbase.zookeeper.property.clientPort", "2181"); } public static void main(String[] args) throws Exception { HBaseAdmin admin = new HBaseAdmin(configuration); if (admin.tableExists("riapguh")) { System.out.println("删除 table"); admin.disableTable("riapguh"); admin.deleteTable("riapguh"); } //创建riapguh表 System.out.println("创建 table"); HTableDescriptor tableDescripter = new HTableDescriptor("riapguh".getBytes());//创建表 tableDescripter.addFamily(new HColumnDescriptor("user"));//创建列簇user tableDescripter.addFamily(new HColumnDescriptor("dpt"));//创建列簇dpt admin.createTable(tableDescripter); HTable table = new HTable(configuration, "riapguh"); //插入数据 System.out.println("add riapguh data"); Listputuser = new ArrayList (); Put user1 = new Put(new String("用户A").getBytes()); //写入用户员信息 user1.add(new String("user").getBytes(), new String("user_code").getBytes(), new String("u_0001").getBytes()); user1.add(new String("user").getBytes(), new String("user_name").getBytes(), new String("u_用户A").getBytes()); //写入部门信息 user1.add(new String("dpt").getBytes(), new String("dpt_code").getBytes(), new String("d_001").getBytes()); user1.add(new String("dpt").getBytes(), new String("dpt_name").getBytes(), new String("d_部门A").getBytes()); putuser.add(user1); Put user2 = new Put(new String("用户B").getBytes()); //写入用户员信息 user2.add(new String("user").getBytes(), new String("user_code").getBytes(), new String("u_0002").getBytes()); user2.add(new String("user").getBytes(), new String("user_name").getBytes(), new String("u_用户B").getBytes()); //写入部门信息 user2.add(new String("dpt").getBytes(), new String("dpt_code").getBytes(), new String("d_002").getBytes()); user2.add(new String("dpt").getBytes(), new String("dpt_name").getBytes(), new String("d_部门B").getBytes()); putuser.add(user2); Put user3 = new Put(new String("用户C").getBytes()); //写入用户员信息 user3.add(new String("user").getBytes(), new String("user_code").getBytes(), new String("u_0003").getBytes()); user3.add(new String("user").getBytes(), new String("user_name").getBytes(), new String("u_用户C").getBytes()); //写入部门信息 user3.add(new String("dpt").getBytes(), new String("dpt_code").getBytes(), new String("d_003").getBytes()); user3.add(new String("dpt").getBytes(), new String("dpt_name").getBytes(), new String("d_部门C").getBytes()); putuser.add(user3); table.put(putuser); table.flushCommits(); //更新用户B Put updateb = new Put(new String("用户B").getBytes()); //写入用户员信息 updateb.add(new String("user").getBytes(), new String("user_code").getBytes(), new String("u_000xsx").getBytes()); updateb.add(new String("user").getBytes(), new String("user_name").getBytes(), new String("u_用户xsx").getBytes()); //写入部门信息 updateb.add(new String("dpt").getBytes(), new String("dpt_code").getBytes(), new String("d_00xsx").getBytes()); updateb.add(new String("dpt").getBytes(), new String("dpt_name").getBytes(), new String("d_部门xsx").getBytes()); table.put(updateb); table.flushCommits(); //HBaseBasic.selectByRowKey("riapguh"); System.out.println("-------------删除用户C---------------------"); //删除用户C //able.delete(new Delete(new String("用户C").getBytes())); List deld = new ArrayList (); deld.add(new Delete(new String("用户C").getBytes())); table.delete(deld); table.flushCommits(); //HBaseBasic.selectByRowKey("riapguh"); } }
"hbase中创建表、插入数据,更新数据,删除数据的操作"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!
用户
部门
数据
信息
员信息
更新
中创
内容
更多
知识
实用
学有所成
接下来
人员
代码
困境
实际
情况
文章
案例
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
河南租服务器哪家最好云空间
网络安全 初中班会ppt
用数据库检索课程号
网络安全教育研究现状
serv文件传送服务器
通辽 网络安全
数据库技术发展的内在驱动是什么
安卓魔盒服务器搭建价格
网络安全四个毛笔字
软件开发大公司还是小公司
湛江web安全网络安全培训
重庆收集客户外贸软件开发公司
云端做代理服务器
网络安全四年级简单手抄报字少
vs网站数据库如何连接
做软件开发 腰疼
道路汽车网络安全
华显软件开发服务
数据文件是数据库对象吗
数据库编译密码
csgo国服陀螺有哪些服务器
陕西金盾网络技术服务有限公司
江苏工控软件开发哪家实惠
js获取服务器时间
泉州护苗网络安全课2021
编程软件开发好学吗
互联网软件开发资费
盘古网络技术有限公司董事长
湖南电子网络技术学院
数据库在生活有哪些具体应用