使用java连接ranger+ldap认证的hive,通过jdbc加上用户名密码即可,代码示例如下:
import java.sql.*; public class JdbcHiveLdap { private static String driverName = "org.apache.hive.jdbc.HiveDriver"; public static void main(String[] args) throws SQLException { try { Class.forName(driverName); } catch (ClassNotFoundException e) { e.printStackTrace(); System.exit(1); } // Hive2 JDBC URL with LDAP String jdbcURL = "jdbc:hive2://ip:10000/default"; Connection conn = DriverManager.getConnection(jdbcURL,"username","password"); PreparedStatement ps = conn.prepareStatement("show databases"); ResultSet rs = ps.executeQuery(); while (rs.next()) { System.out.println("hive数据库:"+rs.getString(1)); } conn.close(); } }
标签:jdbc,java,String,hive,ranger,ldap,conn From: https://www.cnblogs.com/kevinlucky/p/16808690.html