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. cmake应用

    2021-01-18

  2. AOP reading notes

    2022-10-10

  3. vi编译器查询手册

    2020-09-23

  4. Java IO流

    2020-07-31

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.

October 2025
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

Life Logs

  1. 回首

    2023-07-14

Return Top