Hbase-Client 1.x新版API操作大全

原创
2018/01/30 18:26
阅读数 6.4K

    某佰的教程太老了,很多都是过时的API,一些方法在eclipse中显示都带有横划线的,看的很脏乱,而且还有印刷错误,故花了几天时间四处搜罗资料把Hbase1.x的API整理了一下 ,本文的java程序全部基于HBase client 1.x以上版本 写了一套example分门别类的列出来给大家分享(带有详细中文注释) 

 

ALTER表相关操作

1. 添加列族

package com.chenjun.hbtest.example.alter;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.HBaseAdmin;

import com.google.protobuf.ServiceException;

/**
 * 使用Java API添加一列族
 * 下面给出的是一个完整的程序,用于添加一列族到现有的表。
 * @author CJ
 */
public class AddColoumn {

	public static void main(String[] args) throws MasterNotRunningException, IOException, ServiceException {
		// new一个配置对象
		Configuration conf = HBaseConfiguration.create();
		Connection conn = ConnectionFactory.createConnection(conf);
		HBaseAdmin.checkHBaseAvailable(conf);
		Admin admin = conn.getAdmin();

		// 初始化列描述对象
		HColumnDescriptor columnDescriptor = new HColumnDescriptor("contactDetails");

		// 添加一个列族
		admin.addColumn(TableName.valueOf("employee"), columnDescriptor);
		System.out.println("coloumn added");
	}

}

2. 删除列族

package com.chenjun.hbtest.example.alter;

import java.io.IOException;
import java.nio.charset.Charset;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.HBaseAdmin;

import com.google.protobuf.ServiceException;

/**
 * @author CJ
 *
 * 使用Java API删除列族
 * 可以使用HBAseAdmin类的deleteColumn()方法删除列族。按照下面给出的步骤添加一个列族到表中。
 */
public class DeleteColoumn {

	public static void main(String[] args) throws MasterNotRunningException, IOException, ServiceException {
		// new一个配置对象
		Configuration conf = HBaseConfiguration.create();
		Connection conn = ConnectionFactory.createConnection(conf);
		HBaseAdmin.checkHBaseAvailable(conf);
		Admin admin = conn.getAdmin();

		// 使用deleteColumn()方法delete列族。传递表名和列族名作为这个方法的参数。
		admin.deleteColumn(TableName.valueOf("TableName"), "contactDetails".getBytes(Charset.forName("UTF-8")));
		System.out.println("列族已删除");
	}

}

3. 创建一个表

package com.chenjun.hbtest.example.alter;

import java.io.IOException;

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.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.HBaseAdmin;

import com.google.protobuf.ServiceException;

/**
 * 使用Java API创建一个表
 * 可以使用HBaseAdmin类的createTable()方法创建表在HBase中。
 * 这个类属于org.apache.hadoop.hbase.client 包。下面给出的步骤是来使用Java API创建表在HBase中。
 * 
 * @author CJ
 */

public class CreateTable {
	public static void main(String[] args) throws IOException, ServiceException {
		//new一个配置对象
		Configuration conf = HBaseConfiguration.create();
		Connection conn = ConnectionFactory.createConnection(conf);
		HBaseAdmin.checkHBaseAvailable(conf);
		Admin admin = conn.getAdmin();

		//初始化表描述
		HTableDescriptor tableDescriptor = new HTableDescriptor(TableName.valueOf("emp"));

		//给表描述对象增加列族
		tableDescriptor.addFamily(new HColumnDescriptor("personal"));
		tableDescriptor.addFamily(new HColumnDescriptor("professional"));

		//让admin根据tableDescriptor执行建表操作
		admin.createTable(tableDescriptor);
		System.out.println("hbase表创建成功! 表名为emp,列族有personal , professional");
	}
}

4. 删除表

package com.chenjun.hbtest.example.alter;

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.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.HBaseAdmin;

import com.google.protobuf.ServiceException;

/**
 * 使用Java API删除表 在删除一个表之前必须先将其禁用。
 * 
 * @author CJ
 */
public class DeleteTable {

	public static void main(String[] args) throws IOException, ServiceException {
		// new一个配置对象
		Configuration conf = HBaseConfiguration.create();
		Connection conn = ConnectionFactory.createConnection(conf);
		HBaseAdmin.checkHBaseAvailable(conf);
		Admin admin = conn.getAdmin();
		// 禁用
		admin.disableTable(TableName.valueOf("emp"));
		// 删除
		admin.deleteTable(TableName.valueOf("emp12"));
		System.out.println("Table deleted");
	}

}

增删改查操作

1.全扫描表

package com.chenjun.hbtest.example.crud;
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.util.Bytes;

import com.google.protobuf.ServiceException;

import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;

/**
 * 使用Java API扫描
 * 使用Java API扫描整个表的数据的完整程序如下:
 * 
 * @author CJ
 */
public class FullScanTable {

	public static void main(String[] args) throws IOException, ServiceException {
		// new一个配置对象
		Configuration conf = HBaseConfiguration.create();
		Connection conn = ConnectionFactory.createConnection(conf);
		HBaseAdmin.checkHBaseAvailable(conf);
		Admin admin = conn.getAdmin();

		// 用表名实例化HTable对象
		String tableName = "emp";
		TableName tn = TableName.valueOf(tableName);
		HTable hTable = null;
		if (admin.tableExists(tn)) {
			hTable = (HTable) conn.getTable(tn);
		} else {
			System.err.println("此表不存在");
			System.exit(-1);
		}

		Scan scan = new Scan();

		// 扫描需要的列族和列
		scan.addColumn(Bytes.toBytes("personal"), Bytes.toBytes("name"));
		scan.addColumn(Bytes.toBytes("personal"), Bytes.toBytes("city"));

		// 获取扫描结果
		ResultScanner scanner = hTable.getScanner(scan);

		// 遍历scan结果
		for (Result result = scanner.next(); result != null; result = scanner.next()) {
			System.out.println("Found row : " + result);
		}
		scanner.close();
	}

}

2.范围扫描表

package com.chenjun.hbtest.example.crud;

import java.io.IOException;
import java.util.List;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.util.Bytes;

import com.google.protobuf.ServiceException;

/**
 * 用JAVA API通过行键范围扫描HBase的操作
 * @author CJ
 */
public class RangeScanTable {
	public static void main(String[] args) throws IOException, ServiceException {
		// new一个配置对象
		Configuration conf = HBaseConfiguration.create();
		Connection conn = ConnectionFactory.createConnection(conf);
		HBaseAdmin.checkHBaseAvailable(conf);
		Admin admin = conn.getAdmin();

		// 用表名实例化HTable对象
		String tableName = "emp";
		TableName tn = TableName.valueOf(tableName);
		HTable hTable = null;
		if (admin.tableExists(tn)) {
			hTable = (HTable) conn.getTable(tn);
		} else {
			System.err.println("此表不存在");
			System.exit(-1);
		}
		//行键的开始值
		String beginRowKey = "1";
		//行键的结束值
		String endRowKey = "2";
		Scan scan = new Scan(Bytes.toBytes(beginRowKey), Bytes.toBytes(endRowKey));
		ResultScanner result = hTable.getScanner(scan);
		for (Result item : result) {
			String rowKey = Bytes.toString(item.getRow());
			//参数:列族,列名
			List<Cell> cells = item.getColumnCells(Bytes.toBytes("self"), Bytes.toBytes("name"));
			//最新的值排在前面,所以取cells的第一个元素
			System.out.println("rowKey:"+rowKey+"  "+"cell:"+cells.get(0));
		}
		
	}
}

3.插入数据

package com.chenjun.hbtest.example.crud;

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.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;

import com.google.protobuf.ServiceException;

/**
 * 使用Java API插入数据
 * 可以使用Put 类的add()方法将数据插入到HBase。
 * 可以使用HTable类的put()方法保存数据。这些类属于org.apache.hadoop.hbase.client包
 * 
 * @author CJ
 */
public class InsertData {

	public static void main(String[] args) throws IOException, ServiceException {
		//new一个配置对象
		Configuration conf = HBaseConfiguration.create();
		Connection conn = ConnectionFactory.createConnection(conf);
		HBaseAdmin.checkHBaseAvailable(conf);
		Admin admin = conn.getAdmin();

		String tableName = "emp";
		TableName tn = TableName.valueOf(tableName);
		HTable hTable = null;
		
		if (admin.tableExists(tn)) {
			hTable = (HTable) conn.getTable(tn);
		} else {
			System.err.println("此表不存在");
			System.exit(-1);
		}

		// 用rowKey实例化Put类
		Put p = new Put(Bytes.toBytes("row1"));
		
		//参数:列族,列名,列值
		p.addColumn(Bytes.toBytes("personal"), Bytes.toBytes("name"), Bytes.toBytes("raju"));

		p.addColumn(Bytes.toBytes("personal"), Bytes.toBytes("city"), Bytes.toBytes("hyderabad"));

		p.addColumn(Bytes.toBytes("professional"), Bytes.toBytes("designation"), Bytes.toBytes("manager"));

		p.addColumn(Bytes.toBytes("professional"), Bytes.toBytes("salary"), Bytes.toBytes("50000"));

		hTable.put(p);
		System.out.println("data inserted");
		hTable.close();
	}

}

4.查询数据

package com.chenjun.hbtest.example.crud;

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.Admin;
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.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;

import com.google.protobuf.ServiceException;

/**
 * 使用Java API读取数据 从一个HBase表中读取数据,要使用HTable类的get()方法。这种方法需要Get类的一个实例
 * 
 * @author CJ
 */
public class ReadData {
	public static void main(String[] args) throws IOException, ServiceException {
		// new一个配置对象
		Configuration conf = HBaseConfiguration.create();
		Connection conn = ConnectionFactory.createConnection(conf);
		HBaseAdmin.checkHBaseAvailable(conf);
		Admin admin = conn.getAdmin();

		// 用表名实例化HTable对象
		String tableName = "emp";
		TableName tn = TableName.valueOf(tableName);
		HTable hTable = null;
		if (admin.tableExists(tn)) {
			hTable = (HTable) conn.getTable(tn);
		} else {
			System.err.println("此表不存在");
			System.exit(-1);
		}

		// 用RowKey实例化Get对象
		Get g = new Get(Bytes.toBytes("row1"));

		// 读取数据
		Result result = hTable.get(g);

		// 根据列族和列取出数据
		byte[] value = result.getValue(Bytes.toBytes("personal"), Bytes.toBytes("name"));
		byte[] value1 = result.getValue(Bytes.toBytes("personal"), Bytes.toBytes("city"));

		//byte[]转String 
		String name = Bytes.toString(value);
		String city = Bytes.toString(value1);
		
		//打印输出结果
		System.out.println("name: " + name + " city: " + city);
	}
}

5.更新数据

package com.chenjun.hbtest.example.crud;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;

import com.google.protobuf.ServiceException;

/**
 * 使用Java API更新数据 使用put()方法将特定单元格更新数据
 * 
 * @author CJ
 */
public class UpdateData {

	public static void main(String[] args) throws MasterNotRunningException, ZooKeeperConnectionException, ServiceException, IOException {
		// new一个配置对象
		Configuration conf = HBaseConfiguration.create();
		Connection conn = ConnectionFactory.createConnection(conf);
		HBaseAdmin.checkHBaseAvailable(conf);
		Admin admin = conn.getAdmin();

		String tableName = "emp";
		TableName tn = TableName.valueOf(tableName);
		HTable hTable = null;
		if (admin.tableExists(tn)) {
			hTable = (HTable) conn.getTable(tn);
		} else {
			System.err.println("此表不存在");
			System.exit(-1);
		}
		// 用rowKey实例化Put对象
		Put p = new Put(Bytes.toBytes("row1"));
		p.addColumn(Bytes.toBytes("personal"), Bytes.toBytes("city"), Bytes.toBytes("Delih"));
		hTable.put(p);
		System.out.println("data Updated");
		//关闭表
		hTable.close();
	}

}

6.删除数据

package com.chenjun.hbtest.example.crud;

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.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
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.util.Bytes;

import com.google.protobuf.ServiceException;

/**
 * 使用Java API删除数据 可以从使用HTable类的delete()方法删除HBase表数据
 * 
 * @author CJ
 */
public class DeleteData {

	public static void main(String[] args) throws IOException, ServiceException {
		// new一个配置对象
		Configuration conf = HBaseConfiguration.create();
		Connection conn = ConnectionFactory.createConnection(conf);
		HBaseAdmin.checkHBaseAvailable(conf);
		Admin admin = conn.getAdmin();

		// 用表名实例化HTable对象
		String tableName = "emp";
		TableName tn = TableName.valueOf(tableName);
		HTable hTable = null;
		if (admin.tableExists(tn)) {
			hTable = (HTable) conn.getTable(tn);
		} else {
			System.err.println("此表不存在");
			System.exit(-1);
		}

		// 用rowKey实例化Delete对象
		Delete delete = new Delete(Bytes.toBytes("row1"));
		//制定要删除的列族和列
		delete.addColumn(Bytes.toBytes("personal"), Bytes.toBytes("name"));
		delete.addFamily(Bytes.toBytes("professional"));

		// 执行删除
		hTable.delete(delete);

		// closing the HTable object
		hTable.close();
		System.out.println("data deleted.....");
	}

}

其他操作

1.禁用表

package com.chenjun.hbtest.example.other;

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.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.HBaseAdmin;

import com.google.protobuf.ServiceException;

/**
 * 禁用表使用Java API 要验证一个表是否被禁用,使用isTableDisabled()方法 和disableTable()方法禁用一个表。
 * 这些方法属于HBaseAdmin类。
 * 
 * @author CJ
 */
public class DisableTable {
	public static void main(String[] args) throws IOException, ServiceException {
		// new一个配置对象
		Configuration conf = HBaseConfiguration.create();
		Connection conn = ConnectionFactory.createConnection(conf);
		HBaseAdmin.checkHBaseAvailable(conf);
		Admin admin = conn.getAdmin();

		// 检查表是否禁用。
		Boolean bool = admin.isTableDisabled(TableName.valueOf("emp"));
		System.out.println(bool);

		// 使用HBaseAdmin对象禁用表。
		if (!bool) {
			admin.disableTable(TableName.valueOf("emp"));
			System.out.println("表[emp]已经被禁用");
		}
	}

}

2.启用表

package com.chenjun.hbtest.example.other;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.HBaseAdmin;

import com.google.protobuf.ServiceException;

/**
 * 使用Java API启用表
 * 要验证一个表是否被启用,使用isTableEnabled()方法;并且使用enableTable()方法使一个表启用。
 * 这些方法属于HBaseAdmin类。按照下面给出启用表的步骤。
 * 
 * @author CJ
 */
public class EnableTable {

	public static void main(String[] args) throws MasterNotRunningException, IOException, ServiceException {
		// new一个配置对象
		Configuration conf = HBaseConfiguration.create();
		Connection conn = ConnectionFactory.createConnection(conf);
		HBaseAdmin.checkHBaseAvailable(conf);
		Admin admin = conn.getAdmin();

		// 检查表是否启用。
		Boolean bool = admin.isTableEnabled(TableName.valueOf("emp"));
		System.out.println(bool);

		// Disabling the table using HBaseAdmin object
		if (!bool) {
			admin.enableTable(TableName.valueOf("emp"));
			System.out.println("Table[emp]已经启用");
		}
	}

}

3.列出所有表

package com.chenjun.hbtest.example.other;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.HBaseAdmin;

import com.google.protobuf.ServiceException;

/**
 * 使用Java API列出表
 * 按照下面给出的步骤来使用Java API从HBase获得表的列表。
 * 
 * @author CJ
 */
public class ListTables {

	public static void main(String[] args) throws IOException, ServiceException {
		//new一个配置对象
		Configuration conf = HBaseConfiguration.create();
		Connection conn = ConnectionFactory.createConnection(conf);
		HBaseAdmin.checkHBaseAvailable(conf);
		Admin admin = conn.getAdmin();

		//根据admin获取表描述
		HTableDescriptor[] tableDescriptor = admin.listTables();

		//打印所有的表名
		for (int i = 0; i < tableDescriptor.length; i++) {
			System.out.println(tableDescriptor[i].getNameAsString());
		}
	}

}

4.判断某表是否存在

package com.chenjun.hbtest.example.other;

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.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.HBaseAdmin;

import com.google.protobuf.ServiceException;

/**
 * 使用Java API验证表的存在
 * 可以使用HBaseAdmin类的tableExists()方法验证表在HBase中是否存在。按照下面给出的步骤验证HBase表存在。
 * 
 * @author CJ
 */
public class TableExists {

	public static void main(String[] args) throws IOException, ServiceException{
		// new一个配置对象
		Configuration conf = HBaseConfiguration.create();
		Connection conn = ConnectionFactory.createConnection(conf);
		HBaseAdmin.checkHBaseAvailable(conf);
		Admin admin = conn.getAdmin();

		// 验证表是否存在
		boolean bool = admin.tableExists(TableName.valueOf("emp"));
		System.out.println(bool);
	}

}

5.关闭HBase服务

package com.chenjun.hbtest.example.other;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.HBaseAdmin;

import com.google.protobuf.ServiceException;

/**
 * 使用Java API停止HBase
 * 可以使用HBaseAdmin类的shutdown()方法关闭HBase。按照下面给出关闭HBase的步骤
 * 
 * @author CJ
 */

public class ShutDownHbase {

	public static void main(String[] args) throws IOException, ServiceException {
		// new一个配置对象
		Configuration conf = HBaseConfiguration.create();
		Connection conn = ConnectionFactory.createConnection(conf);
		HBaseAdmin.checkHBaseAvailable(conf);
		Admin admin = conn.getAdmin();

		// 停止Hbase
		System.out.println("Shutting down hbase");
		admin.shutdown();
	}

}

 

展开阅读全文
打赏
2
10 收藏
分享
加载中
mark
2018/01/31 20:10
回复
举报
很清晰,大赞
2018/01/31 17:23
回复
举报
先赞一个再说
2018/01/30 18:37
回复
举报
更多评论
打赏
3 评论
10 收藏
2
分享
返回顶部
顶部