[Hive_5] Hive 的 JDBC 编程


0. 说明

  Hive 的 JDBC 编程


1. hiveserver2 介绍

  hiveserver2 是 Hive 的 JDBC 接口,用户可以连接此端口来连接 Hive 服务器

  JDBC 驱动类为 org.apache.hive.jdbc.HiveDriver

  Hive JDBC 的端口为 10000

  Web 页面的为 s101:10002

  查看 hiveserver2 启动成功可以通过以下命令

netstat -anop | grep 10000

 


2. Hive 的 JDBC 编程

  2.1 新建 Moudle

  在项目中新建 Moudle myhive

  2.2 添加依赖

  添加 Hive 的 JDBC 的依赖如下

<dependencies>
    <!-- hive 的 jdbc 依赖 -->
    <dependency>
        <groupId>org.apache.hive</groupId>
        <artifactId>hive-jdbc</artifactId>
        <version>2.1.1</version>
    </dependency>

    <!-- 单元测试 -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
    </dependency>
</dependencies>

  2.3 测试代码编写

  测试通过代码使用 JDBC 连接 Hive 进行查询与插入操作

  Code

  2.4 错误解决方案

 问题描述:

java.lang.RuntimeException: org.apache.hadoop.ipc.RemoteException:User: centos is not allowed to impersonate anonymous

 解决方案:

   在 hive-site.xml 配置文件中禁用连接验证

  hive.server2.enable.doAs=false

# 修改 Hive 配置文件 hive-site.xml
sudo vi /soft/hive/conf/hive-site.xml

# 修改内容
<property>
    <name>hive.server2.enable.doAs</name>
    <value>false</value>
    <description>
      Setting this property to true will have HiveServer2 execute
      Hive operations as the user making the calls to it.
    </description>
</property>

原文地址:https://www.cnblogs.com/share23/p/10174279.html