java调用hive

来源:互联网 发布:域名服务器dns中存放 编辑:程序博客网 时间:2024/06/02 05:59
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

StringdriverName="org.apache.hive.jdbc.HiveDriver";
try{
                  Class.forName(driverName);
                  Connectioncon= DriverManager.getConnection(
                              "jdbc:hive2://192.168.1.126:10000/default","",
                              "");
                  Statementstmt=con.createStatement();
                  Stringsql=" select * from hbt_sampleinfo where key='0000012113af115dfb3c0adcffaacb98'";
                  System.out.println("Running: " +sql);
                  ResultSetres=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(ClassNotFoundExceptione) {
                  e.printStackTrace();
                  System.exit(1);
            }
原创粉丝点击