2016-12-26 55 views
0

我正在使用Presto查詢EMR中的Hive表。我初始化了presto驅動程序並獲得了連接,但是當我嘗試在該連接上執行查詢時,出現錯誤:服務器拒絕連接:http://aws.address/v1/statement使用Presto jdbc驅動程序在Hive中查詢表 - 與「服務器拒絕連接」錯誤失敗

我需要在使用之前設置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(); 
     } 
    } 
} 

回答

0

我需要使用「端口轉發」命令(ssh)才能達到AWS中的presto驅動程序。

相關問題