The Hive Data Warehouse based on Hadoop Javaapi simple Invocation instance, the brief introduction of hive. Hive provides three user interfaces: the CLI,JDBC/ODBC and WebUI CLI, the shell command line JDBC/ODBC is Hive Java, similar to the traditional database JDBC WebGui is accessed through the browser Hive
This article mainly introduces the second type of user interface, directly into the business.
1, Hive Installation:
1 Hive Installation Please refer to the relevant articles on the Web, test only in a Hadoop node installed hive can be.
2 test data file ' \ t ' delimited:
1 Zhangsan
2 Lisi
3 Wangwu
3 The test data will be uploaded to the Linux directory, I placed in:/home/hadoop01/data
2. When using JDBC to develop the Hive program, you must first turn on the Hive remote service interface. Open using the following command:
Java code hive--service hiveserver >/dev/null 2>/dev/null &
3. Test code:
Java code import java.sql.connection; import java.sql.drivermanager; import java.sql.resultset; import java.sql.sqlexception; import java.sql.statement; import org.apache.log4j.logger; /** * hive javaapi * * start hive Remote Service interface command line execution: Hive --service hiveserver >/dev/null 2>/dev/null & * * @ author brother * */ public class hivejdbccli { private static String driverName = " Org.apache.hadoop.hive.jdbc.HiveDriver "; private static string url = "Jdbc:hive://hadoop3:10000/default"; private static string user = "Hive"; private static string password = "MySQL"; private static String sql = ""; private static ResultSet res; private static final logger log = logger.getlogger (HiveJdbcCli.class ); public static void main (String[] args) { Connection conn = null; Statement stmt = null; try { conn = getconn (); &Nbsp; stmt = conn.createstatement (); // First step: The existence of the first delete string tablename = droptable (stmt); // Step Two: Create if not present createtable (stmt, tableName ); // Step Three: View the tables created showtables (stmt, tablename); // perform describe table operations desCribetables (stmt, tablename); // perform load data into table operations loaddata (stmt, tablename); // Executive select * query Operations selectdata (stmt, tablename); // perform regular hive query statistic operations countdata (stmt, tablename); } catch (classnotfoundexception e) { e.printstacktrace (); log.error (drivername + " not found!", e); system.exit (1); } catch (sqlexception e) { e.printstacktrace (); log.error ("Connection error!", e); system.exit (1); } finally { try { if (conn != null) { Conn.close (); &