码迷,mamicode.com
首页 > 编程语言 > 详细

使用java(eclipse)远程连接hive

时间:2016-10-13 11:49:31      阅读:178      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!