Package org.conan.myhadoop.mr;import java.sql.connection;import java.sql.drivermanager;import java.sql.resultset;import java.sql.sqlexception;import java.sql.statement;public class hivejdbcconnection { private static string drivername = "Org.apache.hadoop.hive.jdbc.HiveDriver"; // hive 0.11.0 version after org.apache.hadoop.hive.jdbc.hivedriver private static string url = "Jdbc:hive://localhost:10000/default"; // hive 0.11.0 version after JDBC : hive2://localhost:10000/default private static string username = "; private static string password = " "; public static void main (String[] args) { try { &Nbsp; class.forname (drivername); connection con = drivermanager.getconnection ("url", "UserName", "PassWord"); statement stmt = con.createstatement (); // Delete if it exists String tableName = "Jdbc_table"; String sql = "drop table if exists " + Tablename; stmt.execute (SQL); // Creating Tables sql = "Create table" + tableName + (key string, value string) row format delimited fields terminated by ', ' stored as textfile "; stmt.execute (SQL); //load Data string path= "/home/hive_1.txt"; sql = "load data local inpath ' "+path+" ' into table "+tablename; Stmt.execute (SQL); // querying data sql = "select * from " + tablename; resultset res = stmt.executequery (SQL); while ( Res.next ()) { System.out.println (res.getstring (1) + "\ T" +res.getstring (1)); } } catch (classnotfoundexception e) { system.out.println ("Driver class not found"); E.printstacktrace (); } catch (SQLException e) { system.out.println (" There is a problem connecting hive information "); e.printstacktrace (); } }}
The above is connected with Java Hiveserver, and Hiveserver itself has many problems (such as security, concurrency, etc.), for these problems, The Hive0.11.0 version offers a whole new service: HiveServer2, a good solution to the security, concurrency, and so on, of Hiveserver.
The username and password above are the hive metadata MySQL username and password
Reference article:
http://www.iteblog.com/archives/846
This article is from the "Nothing qq:934033381" blog, please be sure to keep this source http://tianxingzhe.blog.51cto.com/3390077/1698639
HIVE JDBC Connection detailed