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. linux文件系统

    2020-11-27

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

    2020-08-28

  3. AOP reading notes

    2022-10-10

  4. 链接原理浅析(基于Unix ELF文件格式)

    2022-01-23

There are no comment yet.

COMMENT

Take a Coffee Break

Recommend post

  1. 常用工具指令

    2022-09-18

Category list

ABOUT

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

May 2025
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031  

Life Logs

  1. 回首

    2023-07-14

Return Top