使用 Presto jdbc 驱动程序在 Hive 中查询表 - 失败并出现"Server refused connection"错误



我正在使用presto查询EMR中的蜂巢表。我初始化了Presto驱动程序并获得连接,但是当我尝试在该连接上执行查询时,我会收到一个错误:服务器拒绝连接:http://aws.address/v1/statement。

使用之前,我是否需要设置Hive/AWS凭据?我该怎么办?

public void init() {
    try {
        Class.forName("com.facebook.presto.jdbc.PrestoDriver");
        if(connection == null)
            connection = DriverManager.getConnection(url,username,password);
            // url = "jdbc:presto://aws.address:8889/hive/default"
        } catch (ClassNotFoundException | SQLException e) {
            // TOD: handle exception
            e.printStackTrace();
        }
    }
public void executeMyQuery() {
    if(connection == null) {
        connection = driver.getConnection();
    }
    ResultSet resultSet = null;
    Statement stmt = connection.createStatement();
    try {
        resultSet = stmt.executeQuery(query);
    } catch (Exception e) {
        logger.error("Failed to execute query, with error: ",e);
    } finally {
        if(resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if(stmt != null){
            stmt.close();
        }
    }
}

我需要使用'端口转发'命令(SSH)才能在AWS中接触Presto驱动程序。

相关内容