1、maven pom坐标引入jar
<repositories>
<!--cloudera仓库地址-->
<repository>
<id>cloudera</id>
<url>https://repository.cloudera.com/artifactory/cloudera-repos/</url>
</repository>
</repositories>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-client</artifactId>
<version>1.2.0-cdh5.12.2</version>
</dependency>
2、基本操作,代码如下.
import java.io.IOException;
import java.math.BigInteger;
import java.util.*;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.NamespaceDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.filter.Filter;
import org.apache.hadoop.hbase.filter.PageFilter;
import org.apache.hadoop.hbase.util.Bytes;
public class HbaseUtil{
protected static Configuration conf = null;
protected static Connection connection=null;
protected static Admin admin = null;
/**
* @desc 取得连接
*/
public static void getHbaseConnection(){
try {
conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum","192.168.172.71,192.168.172.72,192.168.172.73");//zookeeper地址
connection=ConnectionFactory.createConnection(conf);
admin=connection.getAdmin();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* @desc 连关闭接
*/
public static void close(){
try {
if (connection!=null) {
connection.close();
}
if (admin!=null) {
admin.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* @desc 创建表
*/
public static void createTable(String nameSpace,String tableName, String family,byte[][] splitKeys){
try {
// 创建表空间
// NamespaceDescriptor descriptor=NamespaceDescriptor.create(nameSpace).build();
// admin.createNamespace(descriptor);
TableName tName=TableName.valueOf(nameSpace,tab