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);
            }
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值