zoukankan      html  css  js  c++  java
  • hive 创建表和导入数据实例

    //创建数据库
    create datebase hive;
    //创建表
    create table t_emp(
    id int,
    name string,
    age int,
    dept_name string,
    like array<string>,
    tedian map<string,string>
    )
    row format delimited
    fields terminated by ','
    collection items terminated by '_'
    map keys terminated by ':';

    ap: 1,zhangsan,32,xxx,sports_books_travel,sex:man_color:red

    导入本地文件
    load data local inpath '/root/emp.txt' into table t_emp;

    导出表数据到hdfs
    export table t_emp to '/home/xx_t_emp.txt';

    启动hive服务
    启动hive服务之前修改hive-site.xml中的thrift.bind.*为主机名。
    ./hive --service hiveserver2

    java连接hive代码
    public static void main(String[] args) throws Exception{
    Class.forName("org.apache.hive.jdbc.HiveDriver");
    Connection conn = DriverManager.getConnection("jdbc:hive2://192.168.56.101:10000/default","root","");
    try {
    Statement stat = conn.createStatement();
    ResultSet result = stat.executeQuery("select count(*) from t_emp");
    if(result.next()){
    System.out.println(result.getInt(1));
    }
    } catch (Exception e) {
    e.printStackTrace();
    // TODO: handle exception
    }finally {
    conn.close();
    }
    }

  • 相关阅读:
    Java 回调函数的理解
    Java对象初始化
    Hibernate中get方法和load方法的区别
    Java 如何判断导入表格某列是否有重复数据
    Java学习之Java的单例模式
    Java中怎么设置文件权限
    div居中问题
    JSON
    js
    ajax
  • 原文地址:https://www.cnblogs.com/mowei/p/6694951.html
Copyright © 2011-2022 走看看