Hbase Api简单操作(Java)_javaapi操作hbase,java面试手写代码的多么

先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
img
img
img
img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上Java开发知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以添加V获取:vip1024b (备注Java)
img

正文

package client;

// cc PutExample Example application inserting data into HBase
// vv PutExample
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;
// ^^ PutExample
import util.HBaseHelper;
// vv PutExample

import java.awt.*;
import java.io.IOException;

public class PutExample {

public static void main(String[] args) throws IOException {
Configuration conf = HBaseConfiguration.create(); // co PutExample-1-CreateConf Create the required configuration.
//conf.set(“hbase.zookeeper.quorum”, “hadoop1010,hadoop1011,hadoop1012”);
conf.addResource(“hbase-site.xml”);
// ^^ PutExample
HBaseHelper helper = HBaseHelper.getHelper(conf);
helper.dropTable(“testtable”);
helper.createTable(“testtable”, “colfam1”,“colfam2”);
// vv PutExample
Connection connection = ConnectionFactory.createConnection(conf);
//指定表名
Table table = connection.getTable(TableName.valueOf(“testtable”)); // co PutExample-2-NewTable Instantiate a new client.

//导入数据的rowkey
Put put = new Put(Bytes.toBytes(“row1”)); // co PutExample-3-NewPut Create put with specific row.
//设置导入指定列族:列,值
put.addColumn(Bytes.toBytes(“colfam1”), Bytes.toBytes(“qual1”),
Bytes.toBytes(“val100”)); // co PutExample-4-AddCol1 Add a column, whose name is “colfam1:qual1”, to the put.
put.addColumn(Bytes.toBytes(“colfam1”), Bytes.toBytes(“qual2”),
Bytes.toBytes(“val200”)); // co PutExample-4-AddCol2 Add another column, whose name is “colfam1:qual2”, to the put.
put.addColumn(Bytes.toBytes(“colfam1”), Bytes.toBytes(“qual3”),
Bytes.toBytes(“val300”));
put.addColumn(Bytes.toBytes(“colfam2”), Bytes.toBytes(“qual1”),
Bytes.toBytes(“val300”));

//put入数据
table.put(put); // co PutExample-5-DoPut Store row with column into the HBase table.
//关闭表
table.close(); // co PutExample-6-DoPut Close table and connection instances to free resources.
//关闭连接
connection.close();
// ^^ PutExample
//关闭
helper.close();
// vv PutExample
}
}
// ^^ PutExample

2.查询(get)

package client;

// cc GetExample Example application retrieving data from HBase
import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;

import util.HBaseHelper;

public class GetExample {

public static void main(String[] args) throws IOException {
// vv GetExample
Configuration conf = HBaseConfiguration.create(); // co GetExample-1-CreateConf Create the configuration.

conf.addResource(“hdfs-site.xml”);

// ^^ GetExample
HBaseHelper helper = HBaseHelper.getHelper(conf);
if (!helper.existsTable(“testtable”)) {
helper.createTable(“testtable”, “colfam1”);
}
// vv GetExample
Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(TableName.valueOf(“testtable”)); // co GetExample-2-NewTable Instantiate a new table reference.

Get get = new Get(Bytes.toBytes(“row1”)); // co GetExample-3-NewGet Create get with specific row.

get.addColumn(Bytes.toBytes(“colfam1”), Bytes.toBytes(“qual1”)); // co GetExample-4-AddCol Add a column to the get.

Result result = table.get(get); // co GetExample-5-DoGet Retrieve row with selected columns from HBase.

byte[] val = result.getValue(Bytes.toBytes(“colfam1”),
Bytes.toBytes(“qual1”)); // co GetExample-6-GetValue Get a specific value for the given column.

System.out.println("Value: " + Bytes.toString(val)); // co GetExample-7-Print Print out the value while converting it back.

table.close(); // co GetExample-8-Close Close the table and connection instances to free resources.
connection.close();
// ^^ GetExample
helper.close();
}
}

3.删除操作(delete)

最后

Java架构进阶面试及知识点文档笔记

这份文档共498页,其中包括Java集合,并发编程,JVM,Dubbo,Redis,Spring全家桶,MySQL,Kafka等面试解析及知识点整理

image

Java分布式高级面试问题解析文档

其中都是包括分布式的面试问题解析,内容有分布式消息队列,Redis缓存,分库分表,微服务架构,分布式高可用,读写分离等等!

image

互联网Java程序员面试必备问题解析及文档学习笔记

image

Java架构进阶视频解析合集

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip1024b (备注Java)
img

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

可以添加V获取:vip1024b (备注Java)**
[外链图片转存中…(img-LlmbECJn-1713601916055)]

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值