packagetest;importjava.io.IOException;importjava.util.ArrayList;importjava.util.HashMap;importjava.util.Iterator;importjava.util.List;importjava.util.Map;importjava.util.Set;importjava.util.logging.Logger;importorg.apache.hadoop.conf.Configuration;importorg.apache.hadoop.hbase.Cell;importorg.apache.hadoop.hbase.CellUtil;importorg.apache.hadoop.hbase.CompareOperator;importorg.apache.hadoop.hbase.HBaseConfiguration;importorg.apache.hadoop.hbase.TableName;importorg.apache.hadoop.hbase.client.Admin;importorg.apache.hadoop.hbase.client.ColumnFamilyDescriptor;importorg.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;importorg.apache.hadoop.hbase.client.Connection;importorg.apache.hadoop.hbase.client.ConnectionFactory;importorg.apache.hadoop.hbase.client.Delete;importorg.apache.hadoop.hbase.client.Get;importorg.apache.hadoop.hbase.client.Put;importorg.apache.hadoop.hbase.client.Result;importorg.apache.hadoop.hbase.client.ResultScanner;importorg.apache.hadoop.hbase.client.Scan;importorg.apache.hadoop.hbase.client.Table;importorg.apache.hadoop.hbase.client.TableDescriptor;importorg.apache.hadoop.hbase.client.TableDescriptorBuilder;importorg.apache.hadoop.hbase.filter.BinaryComparator;importorg.apache.hadoop.hbase.filter.ColumnPaginationFilter;importorg.apache.hadoop.hbase.filter.ColumnPrefixFilter;importorg.apache.hadoop.hbase.filter.Filter;importorg.apache.hadoop.hbase.filter.FilterList;importorg.apache.hadoop.hbase.filter.MultipleColumnPrefixFilter;importorg.apache.hadoop.hbase.filter.PageFilter;importorg.apache.hadoop.hbase.filter.PrefixFilter;importorg.apache.hadoop.hbase.filter.RandomRowFilter;importorg.apache.hadoop.hbase.filter.RowFilter;importorg.apache.hadoop.hbase.filter.SkipFilter;importorg.apache.hadoop.hbase.filter.SubstringComparator;importorg.apache.hadoop.hbase.filter.TimestampsFilter;importorg.apache.hadoop.hbase.filter.ValueFilter;importorg.apache.hadoop.hbase.util.Bytes;/***
*@author李小家
**/
public classHbaseClient {private static Logger logger = Logger.getLogger(HbaseClient.class.getName());private static Connection conn = null;/*** 建立连接
**/
static{
System.setProperty("HADOOP_USER_NAME", "lixj");
Configuration conf=HBaseConfiguration.create();
conf.set("hbase.zookeeper.property.clientPort", "2181");
conf.set("hbase.zookeeper.quorum", "39.108.***.***");
conf.set("hadoop.user.name","lixj");try{
conn=ConnectionFactory.createConnection(conf);
}catch(IOException e) {//TODO Auto-generated catch block
e.printStackTrace();
}
}/*** 创建表
*@paramtableName 表名
*@paramfamilys 列族
*@throwsIOException*/
public voidcreateTable(String tableName,String ...familys){try{
Admin admin=conn.getAdmin();
TableName tname=TableName.valueOf(tableName);if( admin.tableExists(tname) ){
logger.warning(tableName+ "表已经存在,不能重复创建.");
}else{
TableDescriptorBuilder tdesc=TableDescriptorBuilder.newBuilder(tname);for(String family: familys){
ColumnFamilyDescriptor cfd=ColumnFamilyDescriptorBuilder.of(family);
tdesc.setColumnFamily(cfd);
}
TableDescriptor desc=tdesc.build();
admin.createTable(desc);
}
}catch(IOException e) {//TODO Auto-generated catch block
e.printStackTrace();
}
}public void createTables(String[] table