zoukankan      html  css  js  c++  java
  • 9月14日

    学习hbase的java api操作

    新建项目后在 pom.xml 中添加依赖:

     获取 Configuration 对象,填入自己配置

    public static Configuration conf;

    static{ //使用 HBaseConfiguration 的单例方法实例化 conf = HBaseConfiguration.create();

    conf.set("hbase.zookeeper.quorum", "192.166.9.102");

    conf.set("hbase.zookeeper.property.clientPort", "2181"); }

    判断表是否存在

    public static boolean isTableExist(String tableName) throws MasterNotRunningException, ZooKeeperConnectionException, IOException{

    //在 HBase 中管理、访问表需要先创建 HBaseAdmin 对象

     //Connection connection = ConnectionFactory.createConnection(conf);

    //HBaseAdmin admin = (HBaseAdmin) connection.getAdmin();

    HBaseAdmin admin = new HBaseAdmin(conf);

    return admin.tableExists(tableName); }

    创建表 public static void createTable(String tableName, String... columnFamily) throws MasterNotRunningException, ZooKeeperConnectionException, IOException{ HBaseAdmin admin = new HBaseAdmin(conf); //判断表是否存在

    if(isTableExist(tableName)){ System.out.println("表" + tableName + "已存在"); //System.exit(0); }

    else{ //创建表属性对象,表名需要转字节 HTableDescriptor descriptor = new HTableDescriptor(TableName.valueOf(tableName)); //创建多个列族

    for(String cf : columnFamily){ descriptor.addFamily(new HColumnDescriptor(cf)); } //根据对表的配置,创建表

    admin.createTable(descriptor);

    System.out.println("表" + tableName + "创建成功!");}

    }

    目前只是在学习,在我本机上不知道为什么实现不了。

    学习时间:17:43到22:47

  • 相关阅读:
    生成函数学习笔记
    CF1437F Emotional Fishermen
    BZOJ 1443 [JSOI2009]游戏Game
    BZOJ 1018 [SHOI2008]堵塞的交通traffic
    访问量破1000之记录
    BZOJ 1022 [SHOI2008]小约翰的游戏John
    BZOJ1457 棋盘游戏
    BZOJ1874: [BeiJing2009 WinterCamp]取石子游戏
    BZOJ 1188 [HNOI2007]分裂游戏
    Codeforces Round #345 (Div. 2)
  • 原文地址:https://www.cnblogs.com/buyaoya-pingdao/p/14901214.html
Copyright © 2011-2022 走看看