Connect to hive remotely using Java (Eclipse)

Source: Internet
Author: User
Tags log4j

Hive version Apache-hive-1.2.1-bin

1. Start MySQL (sevice mysql start), then start the Hive remote service, enter:./hive--service Hiveserver2

Then the command line shows the wait input, no tube here, enter the second step;
2. Introducing the jar package into the project

Jar Package includes: Apache-hive-1.2.1-bin inside the Lib jar package, and hadoop-2.7.1--"share--" hadoop--"common under the Hadoop-common-2.7.1.jar

3. Write the following code in the project
Class.forName ("Org.apache.hive.jdbc.HiveDriver");
Connection Connection = drivermanager.getconnection ("Jdbc:hive2://192.168.18.130:10000/hive", "root", "root");
The connection is created (hive is the database name for hive in MySQL after 10000)

Cases:

public static void Main (string[] args) {
try {

Class.forName ("Org.apache.hive.jdbc.HiveDriver");
Connection Connection = drivermanager.getconnection ("Jdbc:hive2://192.168.18.130:10000/hive", "root", "root");
System.out.println (connection);
} catch (ClassNotFoundException e) {
E.printstacktrace ();
} catch (SQLException e) {
E.printstacktrace ();
}
}

Output Result:

Log4j:warn No Appenders could is found for logger (org.apache.hive.jdbc.Utils).
Log4j:warn Initialize the log4j system properly.
Log4j:warn See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
slf4j:failed to load Class "Org.slf4j.impl.StaticLoggerBinder".
Slf4j:defaulting to No-operation (NOP) Logger implementation
Slf4j:see Http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[Email protected]

Connection Successful!!

Connect to hive remotely using Java (Eclipse)

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.