import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;

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.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Table;


public class A_getAllInfo {
    public static Configuration configuration;
    public static Connection connection;
    public static Admin admin;
    
    /**
     * @param args
     */
    public static void main(String[] args)throws IOException {
        getAllInfo();
        // TODO Auto-generated method stub

    }
    //建立连接
    public static void init(){
        configuration  = HBaseConfiguration.create();
        configuration.set("hbase.rootdir","hdfs://localhost:9000/hbase");
        try{
            connection = ConnectionFactory.createConnection(configuration);
            admin = connection.getAdmin();
        }catch (IOException e){
            e.printStackTrace();
        }
    }
    //关闭连接
    public static void close(){
        try{
            if(admin != null){
                admin.close();
            }
            if(null != connection){
                connection.close();
            }
        }catch (IOException e){
            e.printStackTrace();
        }
    }
    public static void getAllInfo() throws IOException {
        init();
        HTableDescriptor hTableDescriptors[] = admin.listTables();
        for(HTableDescriptor hTableDescriptor :hTableDescriptors){
            System.out.println(hTableDescriptor.getNameAsString());
            Table table = connection.getTable(TableName.valueOf(hTableDescriptor.getNameAsString()));
            HTableDescriptor HTableDes = table.getTableDescriptor();
            Collection<HColumnDescriptor> a = HTableDes.getFamilies();
            Iterator<HColumnDescriptor> it = a.iterator() ;
            while(it.hasNext())
            {
                HColumnDescriptor next = it.next();
                System.out.println(next);
            }
            table.close();
        }
        close();
    }

}

 

相关文章:

  • 2021-07-10
  • 2021-10-15
  • 2021-09-21
  • 2021-10-13
  • 2022-12-23
  • 2022-12-23
  • 2021-05-25
  • 2021-11-02
猜你喜欢
  • 2021-11-29
  • 2022-12-23
  • 2021-09-14
  • 2022-03-02
  • 2021-08-12
相关资源
相似解决方案