Query tables in Hive using Presto jdbc driver - Failed with "Server refused connection" error

490 views Asked by At

I am using Presto to query Hive tables in EMR. I initialized presto driver and get the connection, but when I am trying to execute a query on that connection, I am getting an error: Server refused connection: http://aws.address/v1/statement.

Do I need to set Hive/AWS credentials before using it? How can I do it?

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();
        }
    }
}
1

There are 1 answers

0
Liat On BEST ANSWER

I needed to use 'port forwarding' command (ssh) in order to reach presto driver in AWS.