码迷,mamicode.com
首页 > 数据库 > 详细

Hive 8、Hive2 beeline 和 Hive jdbc

时间:2019-09-11 23:39:22      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:nod   result   void   cal   image   ips   static   for   登录   

1、Hive2 beeline 

Beeline 要与HiveServer2配合使用,支持嵌入模式和远程模式

启动beeline

打开两个Shell窗口,一个启动Hive2 一个beeline连接hive2

#启动HiverServer2 , ./bin/hiveserver2 
[root@node5 ~]# hiveserver2
16/02/23 22:55:25 WARN conf.HiveConf: HiveConf of name hive.metastore.local does not exist

  

#启动Beeline 
# $ ./bin/beeline 下面的方式需要配置Hive的环境变量
[root@node5 ~]# beeline
Beeline version 1.2.1 by Apache Hive
beeline> 

  启动beeline之后可以尝试连接hiveserver2

beeline> !connect jdbc:hive2://node5:10000
Connecting to jdbc:hive2://node5:10000
Enter username for jdbc:hive2://node5:10000: 
#默认 用户名就是登录账号 密码为空

  2、Hive jdbc

打开Eclipse 新建一个Java 项目:

public class Demo {

    public static void main(String[] args) {
        try {
            Class.forName("org.apache.hive.jdbc.HiveDriver");
            Connection conn = DriverManager.getConnection("jdbc:hive2://node5:10000/hive","root","123456");
            String sql = "select * from news";
            Statement sment = conn.createStatement();
            ResultSet rs = sment.executeQuery(sql);
            while(rs.next()){
                HiveQueryResultSet hqrs = (HiveQueryResultSet)rs;
                System.out.println(hqrs.getString(1)+"\t"+hqrs.getString(2));
            }
            conn.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

  在Hive数据库中有这样一个表 news

hive> use hive
    > ;
OK
Time taken: 4.244 seconds
hive> select * from news;
OK
   I‘m tom
   what are you doing
   i‘m ok
Time taken: 1.247 seconds, Fetched: 3 row(s)

  执行完Java代码以后,可以看到数据正常查询出来了

技术图片

 

Hive 8、Hive2 beeline 和 Hive jdbc

标签:nod   result   void   cal   image   ips   static   for   登录   

原文地址:https://www.cnblogs.com/tesla-turing/p/11509313.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!