Hive’s JDBC connection


Related knowledge
Hive is the basic component of data warehouse application in big data technology cluster, and it is the benchmark of other similar data warehouse applications. Basic data operations can be processed by hive client in script mode. If you need to develop applications, you need to use hive’s jdbc driver to connect.
Hive jdbc driver connection is divided into two types, the early one is hiveserver, and the latest one is hiveserver2. The former has many problems, such as security and concurrency, while the latter solves the problems such as security and concurrency.

System environment
Linux Ubuntu 20.04

Task content
Practice using JDBC to connect hive and operate hive through Java code.

Task steps
1. First, create a new / data / hive6 directory in Linux to store the required files.

mkdir -p /data/hive6  

2. Switch to / apps / hive / conf directory, modify hive-site.xml file, and write the following configuration to


3. Switch to / apps / Hadoop / SBIN directory and start Hadoop related processes

cd /apps/hadoop/sbin  

4. Start MySQL service

sudo service mysql start  

5. Switch to the / apps / hive directory and start hiveserver2

cd /apps/hive        
./bin/hive --service hiveserver2 

Hive's JDBC connection

6. Open a terminal simulator and use the netstat command to view port 10000

netstat -nptl | grep 10000  

Hive's JDBC connection

7. Switch to / apps / hive / bin and start beeline

cd /apps/hive/bin  

Hive's JDBC connection

8. Use (! connect jdbc:hive2 : / / IP address: 10000 hiveuser hivepassword) to test whether it can connect. The user name and password are the created user name (root) and password (123456).

!connect jdbc:hive2://  

9. Create a project in idea and add the configuration file in Hadoop to resources
Hive's JDBC connection

10. Add Maven dependency


Hive's JDBC connection


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class HiveClient {
    private static String driverName = "org.apache.hive.jdbc.HiveDriver";
    public static void main(String args[]){
        try {
            Connection con = DriverManager.getConnection("jdbc:hive2://localhost:10000/hive", "root", "123456");

            Statement st =  con.createStatement();
        } catch (ClassNotFoundException e) {
        }catch (SQLException throwables) {