使用ssl:
jdbc:hive2://<host>:<port>/<db>;ssl=true;sslTrustStore=<trust_store_path>;trustStorePassword=<trust_store_password>
trust_store_path:是信任库文件所使用的路径
trust_store_password:密码
- 如果是http模式:
jdbc:hive2://<host>:<port>/<db>;ssl=true;sslTrustStore=<trust_store_path>;trustStorePassword=<trust_store_password>;transportMode=http;httpPath=<http_endpoint>
使用zookeeper服务发现
`jdbc:hive2:///;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2 `zookeeper quorum 同 hive-site.xml/hivserver2-site.xml配置文件中:hive.zookeeper.quorum 一致。
还可以增加额外参数:
jdbc:hive2://<zookeeperquorum>/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2 ?tez.queue.name=hive1&hive.server2.thrift.resultset.serialize.in.tasks=true
使用kerberos认证:
url="jdbc:hive2://xxx.xxx.xxx.xxx:24002,xxx.xxx.xxx.xxx:24002,xxx.xxx.xxx.xxx:24002/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver;sasl.qop=auth-conf;auth=KERBEROS;principal=hive/hadoop.hadoop.com@HADOOP.COM;user.principal=hive/hadoop.hadoop.com;user.keytab=conf/hive.keytab"
在这种url下连接hive不再需要用户名和密码,连接代码如下:
// 建立连接
connection = DriverManager.getConnection(url, "", "");