设为首页 加入收藏

TOP

java调用hive
2019-01-19 13:03:24 】 浏览:70
Tags:java 调用 hive
1 pom.xml

<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.7.2</version>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>2.1.0</version>
</dependency>

2 hive服务器
hive-site.xml 配置hive的认证方式
<property>
<name>hive.server2.authentication</name>
<value>NONE </value>
<description>
Expects one of [nosasl, none, ldap, kerberos, pam, custom].
Client authentication types.
NONE: no authentication check
LDAP: LDAP/AD based authentication
KERBEROS: Kerberos/GSSAPI authentication
CUSTOM: Custom authentication provider
(Use with property hive.server2.custom.authentication.class)
PAM: Pluggable authentication module
NOSASL: Raw transport
</description>


./hive2server &
netstat -nltp|grep 10000



3

String driverName = "org.apache.hive.jdbc.HiveDriver";
try {
Class.forName(driverName);
Connection con = DriverManager.getConnection(
"jdbc:hive2://192.168.1.126:10000/default", "",
"");
Statement stmt = con.createStatement();
String sql = " select * from hbt_sampleinfo where key='0000012113af115dfb3c0adcffaacb98'";
System.out.println("Running: " + sql);
ResultSet res = stmt.executeQuery(sql);
if (res.next()) {
System.out.println(res.getString(1));
System.out.println(res.getString(2));
System.out.println(res.getString(3));
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
System.exit(1);
}
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇hive查询命令 下一篇Hive的Base64使用

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目