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)