无法获得Connect to Hive版本(2.1.0.2.6.3.0-235)

时间:2019-03-06 14:35:26

标签: java hive bigdata database-connection jdbctemplate

无法通过下面的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'

1 个答案:

答案 0 :(得分:0)

我认为存在某些版本不匹配,因为依存关系对我有用。

compile ("javax.servlet:javax.servlet-api:3.1.0")
compile ("org.apache.hive:hive-jdbc:2.2.0")
compile ("org.apache.hive:hive-metastore:3.1.1") 

请尝试一下。