说明
Hive某种意义上来说是一个数据库,也叫做数据仓库,只不过数据最终存储在hdfs上。而且sql最终都被翻译成mapreduce而已,当然查询效率也因此比较低。比较适合数据分析场合,实时性要求不高。访问hive客户端方式很多种,今天说一下jdbc方式访问hive。为了更好表达官网使用原意义,在这里代码部分只做红色备注,但是不做翻译。这样会更加准确。
实战
JDBC
This document describes the JDBC client for the original Hive Server (sometimes called Thrift server or HiveServer1). For information about the HiveServer2 JDBC client, see JDBC in the HiveServer2 Clients document. HiveServer2 use is recommended; the original HiveServer has several concurrency issues and lacks several features available in HiveServer2.
Version information
The original Hive Server was removed from Hive releases starting in version 1.0.0. See HIVE-6977.
For embedded mode, uri is just "jdbc:hive://". For standalone server, uri is "jdbc:hive://host:port/dbname" where host and port are determined by where the Hive server is run. For example, "jdbc:hive://localhost:10000/default". Currently, the only dbname supported is "default".
JDBC Client Sample Code
Running the JDBC Sample Code
以上指的是用shell脚本来编译和运行jdbc程序,其实也可以在eclipse中直接运行上面那段java代码,要把相关jar包导入项目即可。特别注意hadoop2.x版本已经没有hadoop-core*.xml了,而是分散到不同包中,所以需要将hadoop2.x分散jar包汇总导入项目中。
JDBC Client Setup for a Secure Cluster
To configure Hive on a secure cluster, add the directory containing hive-site.xml to the CLASSPATH of the JDBC client.