首页 > 编程语言 > 详细

使用java(eclipse)远程连接hive

时间:2016-10-13 11:47:57      阅读:324      评论:0      收藏:0      [点我收藏+]

hive 版本apache-hive-1.2.1-bin

1.先启动mysql (sevice mysql start),然后启动hive远程服务,输入:./hive --service hiveserver2 即可

  然后命令行会显示等待输入,不用管了这里了,进入第二步吧;
2.引入jar包到项目中

  jar包包括:  apache-hive-1.2.1-bin 里面的lib下的jar包,还有hadoop-2.7.1--》share--》hadoop--》common下的hadoop-common-2.7.1.jar

3.在项目中写入以下代码即可
   Class.forName("org.apache.hive.jdbc.HiveDriver");
   Connection connection = DriverManager.getConnection("jdbc:hive2://192.168.18.130:10000/hive", "root","root");
   连接就创建好了(10000后的hive是hive在mysql中对应的数据库名)

例:

  public static void main(String[] args) {
      try {
   
          Class.forName("org.apache.hive.jdbc.HiveDriver");
          Connection connection = DriverManager.getConnection("jdbc:hive2://192.168.18.130:10000/hive", "root","root");
          System.out.println(connection);
      } catch (ClassNotFoundException e) {
           e.printStackTrace();
      } catch (SQLException e) {
         e.printStackTrace();
      }
   }

输出结果:

log4j:WARN No appenders could be found for logger (org.apache.hive.jdbc.Utils).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
org.apache.hive.jdbc.HiveConnection@fc2a074

 

连接成功!!

使用java(eclipse)远程连接hive

原文:http://www.cnblogs.com/liumingyi/p/5955670.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!