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 manipulation can be handled by using a script called Hive-client. If you need to develop an application, you need to use Hive’s JDBC driver to connect. Hive JDBC driver connections are divided into two types: HiveServer, HiveServer2, HiveServer2, HiveServer2, HiveServer2, HiveServer2, HiveServer2, HiveServer2, HiveServer2, HiveServer2, HiveServer2, HiveServer2.

Linux Ubuntu 20.04 OpenJDK-11.0.11 Hadoop -3.2.2 Mysql-8.0.25

The task content exercises use JDBC to connect to Hive, using Java code to manipulate Hive.


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

mkdir -p /data/hive6  

2. Switch to /apps/hive/conf and change the heive-site.xml file to write the following configuration

<property> <name>hive.server2.thrift.port</name> <value>10000</value> </property> <property> < name > hive. Server2. Thrift. Bind. Host < / name > < value > 127.0.0.1 < value > / < / property >

3. Switch to /apps/hadoop/sbin and start Hadoop related processes

cd /apps/hadoop/sbin  
./start-all.sh  

4. Start MySQL

sudo service mysql start  

5. Switch to /apps/hive and start HiveServer2

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

6. Open a separate terminal emulator and use the netstat command to look at port 10000

netstat -nptl | grep 10000  

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

cd /apps/hive/bin  
./beeline      

8. Use (! Connect JDBC :hive2:// IP address :10000 hiveuser hivePassword)

! Connect the JDBC: hive2: / / 127.0.0.1:10000

9. Create a project in IDEA and add the configuration file from Hadoop to Resources

10. Add Maven dependencies

< the dependency > < groupId > mysql < / groupId > < artifactId > mysql connector - Java < / artifactId > < version > 8.0.25 < / version > </dependency> <dependency> <groupId>org.apache.hive</groupId> <artifactId>hive-jdbc</artifactId> The < version > 2.3.8 < / version > < / dependency >


package my.study.hive; 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 { Class.forName(driverName); Connection con = DriverManager.getConnection("jdbc:hive2://localhost:10000/hive", "root", "123456"); Statement st = con.createStatement(); } catch (ClassNotFoundException e) { e.printStackTrace(); System.exit(1); }catch (SQLException throwables) { throwables.printStackTrace(); }}}