简单的hbase建表实例
package cn.itcast.hbase; //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.KeyValue; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.HBaseAdmin; //import org.apache.hadoop.hbase.client.HTablePool; public class HBaseDemo { public static void main(String[] args) throws Exception { // TODO 自动生成的方法存根 Configuration conf=HBaseConfiguration.create(); //连接zookeeper conf.set("hbase.zookeeper.quorum", "itcast04:2181,itcast05:2181,itcast06:2181"); //conf.set("ha.zookeeper.quorum", "192.168.80.204:2181,192.168.80.205:2181,192.168.80.206:2181"); //获取表的对象hbaseasmin HBaseAdmin admin = new HBaseAdmin(conf); //定义表名 HTableDescriptor htd=new HTableDescriptor(TableName.valueOf("peoples")); //定义表中列族1 HColumnDescriptor hcd_info=new HColumnDescriptor("info"); hcd_info.setMaxVersions(3); //第一列族2 HColumnDescriptor hcd_data=new HColumnDescriptor("data"); htd.addFamily(hcd_info); htd.addFamily(hcd_data); admin.createTable(htd); admin.close(); } }