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

    开始学习java连接hbase

    看视频教程

    在maven中添加依赖

    <dependencies>
    <dependency>
    <groupId>org.apache.hbase</groupId>
    <artifactId>hbase-server</artifactId>
    <version>2.4.5</version>
    </dependency>
    <dependency>
    <groupId>org.apache.hbase</groupId>
    <artifactId>hbase-client</artifactId>
    <version>2.4.5</version>
    </dependency>

    </dependencies>
    进行配置



    创建api类

    这一部分代码初始化连接对象
    static {

    try {
    Configuration configuration = HBaseConfiguration.create();
    configuration.set("hbase.zookeeper.quorum","hadoop102,hadoop103,hadoop104");
    connection = ConnectionFactory.createConnection(configuration);
    admin = connection.getAdmin();
    } catch (IOException e) {
    e.printStackTrace();
    }

    }

    创建表和检验表是否存在
    //1.判断表是否存在
    public static boolean isTableExits(String tablename) throws IOException {

    boolean f=admin.tableExists(TableName.valueOf(tablename));
    return f;

    }

    //2.创建表
    public static void creatTable(String tablename,String...cfs) throws IOException {
    //1.判断列祖是否存在
    if(cfs.length<0){
    System.out.println("请输入列族信息");
    return;
    }
    //2.判断表是否存在
    if(isTableExits(tablename)){
    System.out.println(tablename+"表已存在");
    return;
    }

    //3.创建表描述器
    HTableDescriptor hTableDescriptor = new HTableDescriptor(TableName.valueOf(tablename));
    //4.循环添加列族信息
    for (String cf : cfs) {
    //5.创建列族描述器
    HColumnDescriptor hColumnDescriptor = new HColumnDescriptor(cf);
    //6.添加具体列族信息
    hTableDescriptor.addFamily(hColumnDescriptor);
    }
    //7.创建表
    admin.createTable(hTableDescriptor);
    }


    creatTable("stu","name","age");

    创建表的参数第一个是表名,后面的叫列族,可以看成列名


    学习时间:17:09到21:03
     
     
  • 相关阅读:
    thinkphp引入phpmailer发送邮件
    让火狐的DIV被内容自动撑开
    mysql 日期操作 增减天数、时间转换、时间戳
    [MySQL] 几句MySQL时间筛选SQL语句[进入查看]
    公钥和私钥
    SSI整合搭建Struts2+Spring+Ibatis框架
    目前 NORTON SEP 及各类产品 离线升级包下载及升级方法
    Spring 3.1.1 + Struts 2.3.1.2 + Hibernate 4.1 整合(SSH)
    IIS与asp.net3.5的问题
    SSI框架整合
  • 原文地址:https://www.cnblogs.com/buyaoya-pingdao/p/15264876.html
Copyright © 2011-2022 走看看