Hive通过JavaAPI操作

这篇博客介绍了如何使用Java通过Beeline连接和操作Hive。首先,讲解了启动Hiveserver2和Beeline的步骤,包括端口配置和权限控制设置。接着,讨论了Hive的用户接口,重点放在JDBC/ODBC接口上,提供了Java API操作Hive的简单实例,并给出了相关项目的Maven配置。最后,提到了解决Beeline连接问题的常见方法和参考资料。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Java 想要访问Hive,需要通过beeline的方式连接Hive,hiveserver2提供了一个新的命令行工具beeline,hiveserver2 对 之前的hive做了升级,功能更加强大,它增加了权限控制,要使用beeline需要先启动hiverserver2,再使用beeline连接

基于hadoop的Hive数据仓库JavaAPI简单调用的实例,关于Hive的简介在此不赘述。hive提供了三种用户接口:CLI,JDBC/ODBC和 WebUI

  1. CLI,即Shell命令行
  2. JDBC/ODBC 是 Hive 的Java,与使用传统数据库JDBC的方式类似
  3. WebGUI是通过浏览器访问 Hive
    本文主要介绍的就是第二种用户接口及Beeline的简单使用。

1.Beeline的使用

1.启动hiveserver2

$ hiveserver2

2.启动beeline连接hive

$ beeline -u jdbc:hive2://192.168.150.1:10000 -n hadoop -p

这里写图片描述

参数的解释:
-u:连接url,可以使用IP,也可以使用主机名,端口默认为10000
-n:连接的用户名(注:不是登录hive的用户名,是hive所在服务器登录用户名)
-p:密码,可以不用输入

可以使用如下命令来修改端口号(默认端口号是:10000):

hiveserver2 --hiveconf hive.server2.thrift.port=10001

如果不知道beeline怎么使用,可以使用如下命令来查看beeline的使用帮助

$ beeline --help

具体如下:

[hadoop@hadoop ~]$ beeline --help
Usage: java org.apache.hive.cli.beeline.BeeLine 
   -u <database url>               the JDBC URL to connect to
   -r                              reconnect to last saved connect url (in conjunction with !save)
   -n <username>                   the username to connect as
   -p <password>                   the password to connect as
   -d <driver class>               the driver class to use
   -i <init file>                  script file for initialization
   -e <query>                      query that should be executed
   -f <exec file>                  script file that should be executed
   -w (or) --password-file <password file>  the password file to read password from
   --hiveconf property=value       Use value for given property
   --hivevar name=value            hive variable name and value
                                   This is Hive specific settings in which variables
                                   can be set at session level and referenced in Hive
                                   commands or queries.
   --property-file=<property-file> the file to read connection properties (url, driver, user, password) from
   --color=[true/false]            control whether color is used for display
   --showHeader=[true/false]       show column names in query results
   --headerInterval=ROWS;          the interval between which heades are displayed
   --fastConnect=[true/false]      skip building table/column list for tab-completion
   --autoCommit=[true/false]       enable/disable automatic transaction commit
   --verbose=[true/false]          show verbose error messages and debug info
   --showWarnings=[true/false]     display connection warnings
   --showDbInPrompt=[true/false]   display the current database name in the prompt
   --showNestedErrs=[
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值