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);
}