【发布时间】:2019-07-28 06:21:26
【问题描述】:
无法通过下面的 java 代码连接到 Hive 2.1.0.2.6.3.0-235
遇到错误
ERROR org.apache.hive.jdbc.Utils - Unable to read HiveServer2 configs from ZooKeeper
Exception in thread "main" java.sql.SQLException: Could not open client transport for any of the Server URI's in ZooKeeper: Failed to open new session: java.lang.IllegalArgumentException: hive configuration hive.server2.thrift.resultset.default.fetch.size does not exists.
我使用过以下 Gradle 依赖:
compile group: 'org.apache.hive', name: 'hive-jdbc', version: '3.1.1'
compile group: 'org.apache.hive', name: 'hive-metastore', version: '3.1.1'
compile group: 'org.apache.hive', name: 'hive-exec', version: '3.1.1'
compile group: 'org.apache.hive', name: 'hive-cli', version: '3.1.1'
compile group: 'org.apache.hive', name: 'hive-service', version: '3.1.1'
下面是我的代码:
import java.sql.Connection
import java.sql.DriverManager
class Hive2ConnectionTest {
static String driverClassName = "org.apache.hive.jdbc.HiveDriver"
static String url = "jdbc:hive2://<ip>:<port>/default;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2-hive2"
static String dbUsername = "username"
static String dbPassword = "password"
static void main(String[] args)throws IOException{
try {
Class.forName(driverClassName);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.exit(1);
}
Connection con = (Connection)DriverManager.getConnection(url, dbUsername, dbPassword);
}
}
我也尝试过其他 gradle 依赖版本,但无法连接
version: '1.2.1000.2.4.2.10-1'
version: '2.1.0.2.6.3.0-235'
【问题讨论】:
-
你能在 hiveserver2 路径下检查你的 ZK 命名空间吗?
标签: java hive bigdata database-connection jdbctemplate