Start the service on hive
Hive--service Hiveserver
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/3A/0D/wKiom1O7S-jCADlJAAEOpAeTovk287.jpg "title=" Hive123.jpg "alt=" Wkiom1o7s-jcadljaaeopaetovk287.jpg "/>
Developing in Eclipse
Import the required jar packages (I'm importing the jar packages required by UDF and JDBC to connect hive, which is basically the simplest)
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/3A/0D/wKioL1O7TBqgdcMAAAXp5Qnlzdk218.jpg "title=" Hive124.jpg "alt=" Wkiol1o7tbqgdcmaaaxp5qnlzdk218.jpg "/>
My Code, hive's syntax is not said, you can modify the example of SQL to do their own business. My hive does not have a username or password set. So
Connection con = new Hivejdbc (). getconnection ("Jdbc:hive://192.168.192.138:10000/default", "", "") ;
The latter two parameters I was set to empty
package com.hive.jdbc;import java.sql.connection;import java.sql.drivermanager;import java.sql.resultset;import java.sql.sqlexception;import java.sql.statement;/** * Connecting Hive * @author liqi * */public class HiveJDBC { public static final string drivername = "Org.apache.hadoop.hive.jdbc.HiveDriver" ; /** * Getting Connections */ public connection getconnection (String url, String username,string password) { try { class.forname (DriverName); Connection conn = Drivermanager.getconnection (url, username, pAssword); return conn; } catch (classnotfoundexception e) { e.printstacktrace (); }catch (sqlexception e) { e.printstacktrace (); } return null; } public static void main (string args[]) { connection con = new hivejdbc (). getconnection ( "Jdbc:hive://192.168.192.138:10000/default", ", " " ); try { Statement stmt = Con.createstatement (); string sql = "Show tables"; ResultSet res = Stmt.executequery (SQL); while (Res.next ( )) { sql = "select * from " + res.getstring (1);           SYSTEM.OUT.PRINTLN ("Tables:" + Res.getstring (1)); resultset restable = stmt.executequery (SQL); while ( Restable.next ()) { system.out.println (restable.getstring (2)); } } } catch (sqlexception e) { e.printstacktrace (); } }}
This article is from the "Stud Programmer's Counter attack" blog, make sure to keep this source http://cdelliqi.blog.51cto.com/9028667/1435695