美文网首页
连接hive查询

连接hive查询

作者: chen1null | 来源:发表于2019-03-22 10:13 被阅读0次
    1. pom.xml (来源: https://blog.csdn.net/niityzu/article/details/42639369
      <properties>
      <hive-jdbc.version>1.2.1</hive-jdbc.version>
      <hive-exec.version>1.2.1</hive-exec.version>
      <hive-metastore.version>1.2.1</hive-metastore.version>
      <hive-service.version>1.2.1</hive-service.version>
      <libfb303.version>0.9.3</libfb303.version>
      <hadoop-common.version>2.7.1</hadoop-common.version>
      <httpclient.version>4.5.3</httpclient.version>
      <httpcore.version>4.4.6</httpcore.version>
      </properties>

      <dependencies>
      <dependency>
      <groupId>org.apache.hive</groupId>
      <artifactId>hive-jdbc</artifactId>
      <version>{hive-jdbc.version}</version> </dependency> <dependency> <groupId>org.apache.hive</groupId> <artifactId>hive-exec</artifactId> <version>{hive-exec.version}</version>
      </dependency>
      <dependency>
      <groupId>org.apache.hive</groupId>
      <artifactId>hive-metastore</artifactId>
      <version>{hive-metastore.version}</version> </dependency> <dependency> <groupId>org.apache.hive</groupId> <artifactId>hive-service</artifactId> <version>{hive-service.version}</version>
      </dependency>
      <dependency>
      <groupId>org.apache.thrift</groupId>
      <artifactId>libfb303</artifactId>
      <version>{libfb303.version}</version> <type>pom</type> </dependency> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-common</artifactId> <version>{hadoop-common.version}</version>
      </dependency>
      <dependency>
      <groupId>org.apache.httpcomponents</groupId>
      <artifactId>httpclient</artifactId>
      <version>{httpclient.version}</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpcore</artifactId> <version>{httpcore.version}</version>
      </dependency>
      </dependencies>

    2. 代码
      public class HiveUtil {

      public static Connection getHiveCon() throws ClassNotFoundException, SQLException {
      Connection connection = null;
      Class.forName("org.apache.hive.jdbc.HiveDriver");
      connection = DriverManager.getConnection("jdbc:hive2://ip:21050/;auth=noSasl", "账号", "");
      return connection;
      }

      public static void main(String[] args) throws SQLException, ClassNotFoundException {
      Statement stmt = HiveUtil.getHiveCon().createStatement();
      String sql = " select count(*) from 数据库.表 WHERE dt='20190304' ";
      String rest = "";
      ResultSet res = stmt.executeQuery(sql);
      while (res.next()) {
      rest = res.getString(1);
      System.out.println(rest);
      }
      }
      }

    相关文章

      网友评论

          本文标题:连接hive查询

          本文链接:https://www.haomeiwen.com/subject/lbxlvqtx.html