美文网首页
java访问开启kerberos的Phoenix

java访问开启kerberos的Phoenix

作者: yinkp001 | 来源:发表于2019-08-16 14:52 被阅读0次

TestPhoenix.java

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.Statement;

import java.util.Properties;

public class TestPhoenix {

    /**

    * @author yinkaipeng

    * 访问kerberos下的Phoenix

    */

    public static void main(String[] args) throws Throwable {

        try {

            Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");

        } catch (Exception e) {

            e.printStackTrace();

        }

        System.setProperty("java.security.krb5.conf", "D:\\krb5.conf");

        Properties pps = System.getProperties();

        pps.setProperty("hbase.zookeeper.quorum", "10.1.236.51");

        pps.setProperty("hbase.master.kerberos.principal", "hbase/_HOST@yinkp");

        pps.setProperty("hbase.regionserver.kerberos.principal", "hbase/_HOST@yinkp");

        pps.setProperty("phoenix.queryserver.kerberos.principal", "HTTP/_HOST@yinkp");

        pps.setProperty("hbase.security.authentication", "kerberos");

        pps.setProperty("hadoop.security.authentication", "kerberos");

        pps.setProperty("zookeeper.znode.parent", "/hbase-secure");

        String url = "jdbc:phoenix:10.1.236.51:2181:/hbase-secure:test/host@yinkp:D:\\test.keytab";

        Connection conn = DriverManager.getConnection(url,pps);

        Statement statement = conn.createStatement();

        String sql = "select *  from test.person ";

        long time = System.currentTimeMillis();

        ResultSet rs = statement.executeQuery(sql);

        while (rs.next()) {

            int IDCARDNUM = rs.getInt("IDCARDNUM");

            String NAME = rs.getString("NAME");

            String AGE = rs.getString("AGE");

            String SEX = rs.getString("SEX");

            System.out.println("IDCARDNUM:"+IDCARDNUM+"NAME:"+NAME+"AGE:"+AGE+"SEX:"+SEX);

        }

        long timeUsed = System.currentTimeMillis() - time;

        System.out.println("time " + timeUsed + "mm");

        rs.close();

        statement.close();

        conn.close();

    }

}

相关文章

网友评论

      本文标题:java访问开启kerberos的Phoenix

      本文链接:https://www.haomeiwen.com/subject/evzfsctx.html