Eclipse connects to Hive

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.