创建表
package org.alex.hbasetest;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import java.io.IOException;
import java.net.URISyntaxException;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.filter.Filter;
public class HelloHBase {
public static void main( String[] args ) throws URISyntaxException, IOException
{
Configuration config=HBaseConfiguration.create();
config.addResource(
new Path(ClassLoader.getSystemResource("hbase-site.xml").toURI()));
config.addResource(
new Path(ClassLoader.getSystemResource("core-site.xml").toURI()));
Connection connection=ConnectionFactory.createConnection(config);
TableName tableName=TableName.valueOf("mytable");
HTableDescriptor table=new HTableDescriptor(tableName);
HColumnDescriptor mycf = new HColumnDescriptor("mycf");
table.addFamily(new HColumnDescriptor(mycf));
Admin admin=connection.getAdmin();
admin.createTable(table);
admin.close();
connection.close();
}
}