public class HBaseApp {
public static void main(String[] args) throws IOException {
System.out.println("----");
//1.创建一个配置文件对象
Configuration conf = HBaseConfiguration.create();
//conf.set("hbase.zookeeper.quorum","192.168.3.130");
conf.set("hbase.zookeeper.quorum","hadoop01");
BasicConfigurator.configure();
//2.链接
Connection conn = ConnectionFactory.createConnection(conf);
Admin admin = conn.getAdmin();
System.out.println(admin);
//3.构建命名空间
NamespaceDescriptor descriptor = NamespaceDescriptor.create("test222").build();
admin.createNamespace(descriptor);
admin.close(); //释放资源
}
}
public class HBaseApp2 { public static void main(String[] args) throws IOException { System.out.println("----"); //1.创建一个配置文件对象 Configuration conf = HBaseConfiguration.create(); //conf.set("hbase.zookeeper.quorum","192.168.3.130"); conf.set("hbase.zookeeper.quorum","hadoop01"); BasicConfigurator.configure(); //2.链接 Connection conn = ConnectionFactory.createConnection(conf); Admin admin = conn.getAdmin(); System.out.println(admin); //3.构建命名空间 TableName tableName = TableName.valueOf("test222:t_person"); boolean flag = admin.tableExists(tableName); System.out.println(flag?"存在":"不存在");
admin.close(); //释放资源
}
}
public class HBaseApp3 { public static void main(String[] args) throws IOException { System.out.println("----"); //1.创建一个配置文件对象 Configuration conf = HBaseConfiguration.create(); //conf.set("hbase.zookeeper.quorum","192.168.3.130"); conf.set("hbase.zookeeper.quorum","hadoop01"); BasicConfigurator.configure(); //2.链接 Connection conn = ConnectionFactory.createConnection(conf); Admin admin = conn.getAdmin(); System.out.println(admin); //3.构建命名空间 TableName person = TableName.valueOf("test222:t_person"); //初始化列族信息 HColumnDescriptor info = new HColumnDescriptor("info"); HColumnDescriptor edu = new HColumnDescriptor("edu"); //设置到表中 HTableDescriptor tableDescriptor = new HTableDescriptor(person); tableDescriptor.addFamily(info); tableDescriptor.addFamily(edu); //4.创建表的操作; admin.createTable(tableDescriptor);
admin.close(); //释放资源
}
}
标签:set,admin,System,conf,println,操作,HBASE,out
From: https://blog.51cto.com/teayear/12023714