HIVE JDBC Connection detailed

Source: Internet
Author: User
Tags stmt


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

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.