public static void Test() throws URISyntaxException, IOException
{
System.out.println("开始执行");
//初始化Hbase连接
Configuration configuration = HBaseConfiguration.create();
//加载配置文件
configuration.addResource(new Path(ClassLoader.getSystemResource("hbase-site.xml").toURI()));
configuration.addResource(new Path(ClassLoader.getSystemResource("core-site.xml").toURI()));
Connection connection = ConnectionFactory.createConnection(configuration);
System.out.println("连接成功!");
//设置表名
TableName tableName = TableName.valueOf("xuehu01");
//将表名传递给HTableDescriptor
HTableDescriptor hTableDescriptor = new HTableDescriptor(tableName);
//创建列族
HColumnDescriptor mycg = new HColumnDescriptor("mycg");
//将列族添加进表中
hTableDescriptor.addFamily(mycg);
//Admin是操作表的类,具有创建
Admin admin = connection.getAdmin();
admin.createTable(hTableDescriptor);
if (admin.tableExists(hTableDescriptor.getTableName()))
{
admin.disableTable(hTableDescriptor.getTableName());
admin.deleteTable(hTableDescriptor.getTableName());
}
admin.createTable(hTableDescriptor);
System.out.println("创建列族");
//设置列族的压缩方式为GZ
mycg.setCompactionCompressionType(Compression.Algorithm.GZ);
//把最大版本数修改为ALL.VERSION,其实就是Integer.MAX_VALUE
mycg.setMaxVersions(HConstants.ALL_VERSIONS);
//把列族的定义更新到表定义里面去
hTableDescriptor.modifyFamily(mycg);
//不过此时对表的修改还没有真正执行下去,只有调用Admin类来进行操作的时候才真正开始执行
//当执行了modifyTable方法后,对表的修改才真正完成
admin.modifyTable(tableName,hTableDescriptor);
//删掉之前建立的列族
//首先进行停用表
admin.disableTable(tableName);
//然后进行删除列族
admin.deleteColumn(tableName,"mycf".getBytes("UTF-8"));
admin.deleteTable(tableName);
admin.close();
connection.close();
}