JDBC操作Hive概述

一.服务器配置

  1. 配置beeline
  2. 启动hiveserver2并置后台运行
    nohup hive --service hiveserver2 > /dev/null 2>&1 &

二.pom.xml

<dependencies>
    <dependency>
        <groupId>org.apache.hive</groupId>
        <artifactId>hive-jdbc</artifactId>
        <version>2.1.1</version>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>RELEASE</version>
    </dependency>
</dependencies>

三.Java JDBC操作

public class HiveJDBC {

    private static String driverName = "org.apache.hive.jdbc.HiveDriver";
    private static String url = "jdbc:hive2://node3:10000/mytest";
    private static String user = "root";
    private static String password = "123456";

    private static Connection conn = null;
    private static Statement stmt = null;
    private static ResultSet rs = null;

    public static void main(String[] args) throws Exception {
        Class.forName(driverName);
        conn = DriverManager.getConnection(url,user,password);
        stmt = conn.createStatement();

        String sql = "select * from t_test";
        rs = stmt.executeQuery(sql);
        while(rs.next()){
            System.out.print(rs.getString("name"));
        }

        if ( rs != null) {
            rs.close();
        }
        if (stmt != null) {
            stmt.close();
        }
        if (conn != null) {
            conn.close();
        }
    }
}

Related post

  1. 汇编基础:常用指令(X86)

    2020-08-28

  2. Java 编码

    2020-07-31

  3. Java 容器

    2020-08-03

  4. AOP reading notes

    2022-10-10

There are no comment yet.

COMMENT

Take a Coffee Break

Recommend post

  1. 常用工具指令

    2022-09-18

ABOUT

Welcome to FullStar, a captivating online destination where the realms of software development and personal reflections intertwine.

September 2025
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

Life Logs

  1. 回首

    2023-07-14

Return Top