Hive is not essentially a database, data content is saved in HDFs, metadata and data maps are saved in MySQL.
When Eclipse connects to hive, it needs to start hive as a service, and hive itself provides a way to start the service
First, the Hive service startup mode
Hive--service Hiveserver2
10000 port number for hive service bindings
View the binding state of the 10000 port number
sudo grep 10000
If the 10000 port number is not turned on, a connection denied exception will occur when connecting to hive
Second, the Local Connection hive service
1) Execute Beeline
Beeline
2) Connect Hive Service
!connect jdbd:hive2://Localhost:10000/default
The default user name and password are empty at this time for the connected default database
Iii. Eclipse Connection Hive
Note: The user name that connects to hive is consistent with the user name used by the queried table, or the function that calls hive in the SQL statement will have an SQL statement execution exception (true, pending further confirmation)
Packagecom.whu.hivetest;Importjava.sql.Connection;ImportJava.sql.DriverManager;ImportJava.sql.ResultSet;Importjava.sql.Statement; Public classHivetest {Private Static FinalString URL = "Jdbc:hive2://localhost:10000/default"; Public Static voidMain (string[] args)throwsexception{Class.forName ("Org.apache.hive.jdbc.HiveDriver"); Connection Conn= Drivermanager.getconnection (URL, "Whu", "")); The user name here is consistent with the file owner of the data table on HDFs so that the function that calls hive in the SQL statement does not appear with the SQL statement exception System.out.println ("Link succeeded"); Statement St=conn.createstatement (); ResultSet RS= St.executequery ("SELECT count (*) from T1"); if(Rs.next ()) {System.out.println (Rs.getint (1)); }//While (Rs.next ()) {//System.out.println (rs.getstring (1) + "\ T" +rs.getstring (2) + "\ T" + rs.getstring (3));// } }}
Eclipse connects to Hive