Read Hive Data with JDBC: Guide
To retrieve data from Hive using JDBC, the following steps are required:
- Import the Hive JDBC driver: Begin by importing the Hive JDBC driver (such as Hive JDBC Connector) into your project.
 - Establishing a JDBC connection: Connect to the Hive server using a JDBC connection string, which typically includes the address of the Hive server, port number, and the name of the database to connect to.
 - Create a query statement: Write the SQL statement for the query you want to execute, such as a SELECT statement to retrieve data.
 - Execute a query: Use the Statement or PreparedStatement objects of JDBC to execute the query statement.
 - Retrieve query results: Obtain data from the query results and process it.
 
Here is a simple Java code example that demonstrates how to read data in Hive using JDBC.
import java.sql.*;
public class HiveJDBCExample {
    public static void main(String[] args) {
        try {
            // 加载Hive JDBC驱动程序
            Class.forName("org.apache.hive.jdbc.HiveDriver");
            // 创建JDBC连接
            Connection con = DriverManager.getConnection("jdbc:hive2://localhost:10000/default", "", "");
            // 创建查询语句
            String query = "SELECT * FROM my_table";
            // 执行查询
            Statement stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery(query);
            // 获取查询结果
            while (rs.next()) {
                // 处理数据
                System.out.println(rs.getString(1) + "\t" + rs.getString(2));
            }
            // 关闭连接
            rs.close();
            stmt.close();
            con.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
It is important to note that the address, port, database name, and table name in the connection string in the above code need to be replaced according to your specific situation. Additionally, after executing the query, the query results can be further processed or stored as needed.