Three methods for connecting to the hive Server Client

Source: Internet
Author: User

In the hive/bin directory, enter./hive -- service hiveserver to indicate that hive has started the server mode.

Unlike normal mode, hive starts a server named thrift at the same time.

You don't need to study the principle of this server. You just need to think that it is a person who transmits information. You can send commands to hive and then hive sends the commands to hadoop.

1. Command Line Mode:

./Hive-h127.0.0.1-P10000

Simple and clear, IP and port.

2. JDBC mode:

The name is confusing.
Private Static string drivername = "org. Apache. hadoop. hive. JDBC. hivedriver ";

@ Beforeclass
Public static void beforeclass () throws sqlexception,
Classnotfoundexception {
Class. forname (drivername );
Connection con = drivermanager. getconnection (
"JDBC: Hive: // 127.0.0.1: 10000/Default ","","");
Stmt = con. createstatement ();
}

@ Test
Public void droptable (){
Try {
Res = stmt.exe cutequery ("Drop table" + tablename );
Res = stmt.exe cutequery ("Drop table" + basetable );
// Res = stmt.exe cutequery ("Drop table" + agecount );
} Catch (sqlexception e ){
E. printstacktrace ();
}

}

The preceding Code deletes a table through JDBC.

Compared with traditional JDBC, I think hive's JDBC features and ease of use are much worse.

However, the hive statement style is similar to that of traditional SQL, so people invented this. It's a bit nondescribable. It is not very good in terms of uadf, not very fond of it.


3. Java client

TTransport transport;
Tprotocol protocol;
Hiveclient client;
Transport = new tsocket ("localhost", 10000 );
Protocol = new tbinaryprotocol (transport );
Client = new hiveclient (Protocol );
Transport. open ();
Client.exe cute ("select usercount (userid) from user3 ");
Transport. Close ();

Obviously, we call the hive API to generate a Java hive client, which has the same effect as the command line client.
I like this because UDAF provides perfect support for parameter modification.

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.