• Hive JDBC连接hive(2.1.1)(需要ssl认证)(java)


    Hive JDBC连接hive(2.1.1)(java)

    1.Maven 依赖

     <dependencies>
            <!--hive jdbc依赖 此包有签名需要排除他们-->
            <dependency>
                <groupId>org.apache.hive</groupId>
                <artifactId>hive-jdbc</artifactId>
                <version>2.1.1-cdh6.3.0</version>
            </dependency>
    
        </dependencies>
    

    2.kerberos 或者LDAP认证

    LDAP认证

    代码如下:

    public class HIveJDBC {
    
        private static String driverName = "org.apache.hive.jdbc.HiveDriver";
        private static String HIVE_URL = "jdbc:hive2://cdh-master03:25005/zyh;ssl=true;sslTrustStore=D:/cdh/hive/src/main/ssl/cm-auto-global_truststore.jks;";
        private static String user = "gree1";
        private static String password = "000000";
    
        public static void main(String[] args) throws Exception {
    
            Class.forName(driverName);
    
            Connection conn = DriverManager.getConnection(HIVE_URL, user, password);
    
            Statement st = conn.createStatement();
    
            ResultSet resultSet = st.executeQuery("select  * from zhchivetable");
    
            while (resultSet.next()) {
                System.out.println(resultSet.getString(1));
            }
        }
    }
    
    

    kerberos 认证

    import hivekerberosauth.KuduKerberosAuth;
    
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.Statement;
    
    /**
     * 用于通过hive jdbc 连接hive 测试
     */
    
    public class HIveJDBC {
    
        private static String driverName = "org.apache.hive.jdbc.HiveDriver";
           private static String CONNECTION_URL ="jdbc:hive2://cdh-master03:25005/;ssl=true;sslTrustStore=D:/cdh/hive/src/main/ssl/cm-auto-global_truststore.jks;principal=hive/cdh-master03@GREE.IO";
    
        public static void main(String[] args) throws Exception {
            KuduKerberosAuth.initKerberosENV(false);
    
            Class.forName(driverName);
    
            Connection conn = DriverManager.getConnection(CONNECTION_URL);
    
            Statement st = conn.createStatement();
    
            ResultSet resultSet = st.executeQuery("select  * from zyh.zhchivetable");
    
            while (resultSet.next()) {
                System.out.println(resultSet.getString(1));
            }
        }
    
    }
    
    
    import org.apache.hadoop.security.UserGroupInformation;
    
    public class KuduKerberosAuth {
    
        /**
         * 初始化访问Kerberos访问
         * @param debug 是否启用Kerberos的Debug模式
         */
        public static void initKerberosENV(Boolean debug) {
            try {
                System.setProperty("java.security.krb5.conf","D:\cdh\hive\src\main\kerberos\krb5.conf");
    //            System.setProperty("java.security.krb5.conf","/lvm/data3/zhc/krb5.conf");
                System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
                if (debug){
                    System.setProperty("sun.security.krb5.debug", "true");
                }
                 UserGroupInformation.loginUserFromKeytab("gree1@GREE.IO", "D:\cdh\hive\src\main\kerberos\gree1.keytab");
    //            UserGroupInformation.loginUserFromKeytab("gree1@GREE.IO", "/lvm/data3/zhc/gree1.keytab");
                 System.out.println(UserGroupInformation.getCurrentUser());
            } catch(Exception e) {
                e.printStackTrace();
            }
        }
    }
    
  • 相关阅读:
    2.安卓体系结构
    1.Android的历史与安装
    Mysql免安装配置
    安装gulp
    搭建vue开发环境的步骤
    运行一个从GitHub上下载的vue项目的具体步骤
    网站源码,大量HTML5模板,视频源码,黑客技术资源
    bootstrap文件树
    jQuery unbind 某个function
    响应式设计的思考:媒体查询(media query)
  • 原文地址:https://www.cnblogs.com/HarSenZhao/p/11510904.html
Copyright © 2020-2023  润新知