HBase Shell API 操作
创建工程
本实验的环境实在ubuntu18.04下完成,首先在改虚拟机中安装开发工具eclipse。
然后创建Java项目名字叫hbase-test








配置运行环境
在src下创建HBaseDemo类

然后编写init方法和close方法,一个创建与HBASE的连接,一个关闭连接。
/**
* 创建连接返回admin
*/
public static void init() {
configuration = HBaseConfiguration.create();
configuration.set("hbase.rootdir", "file:///usr/local/hbase/hbase-tmp");
// configuration.set("hbase.zookeeper.quorum", "hadoop02");
try {
connection = ConnectionFactory.createConnection(configuration);
admin = connection.getAdmin();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 连接关闭
*/
public static void close() {
try {
if (admin != null) {
admin.close();
}
if (null != connection) {
connection.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
建表操作
/**
* 创建表方法
*
* @param myTableName
* @param colFamily
* @throws IOException
*/
public static void createTable(String myTableName, String[] colFamily) throws IOException {
TableName tableName = TableName.valueOf(myTableName);
if (admin.tableExists(tableName)) {
System.out.println("talbe is exists!");

本文档详细介绍了如何使用Java API在HBase Shell中进行操作,包括创建工程、配置环境、建表、查看表名、删除表、删除列、添加数据及查询数据等步骤,提供了具体的代码示例和执行结果。
最低0.47元/天 解锁文章
930

被折叠的 条评论
为什么被折叠?



