2017-12-18 79 views

回答

2

Presto提供了一個正常的JDBC驅動程序,允許您運行SQL查詢。所有你需要做的就是把它包含在你的Java應用程序中。對於如何連接到普雷斯托集羣在其網站上https://prestodb.io/docs/current/installation/jdbc.html一個例子:

// URL parameters 
String url = "jdbc:presto://example.net:8080/hive/sales"; 
Properties properties = new Properties(); 
properties.setProperty("user", "test"); 
properties.setProperty("password", "secret"); 
properties.setProperty("SSL", "true"); 
Connection connection = DriverManager.getConnection(url, properties); 

// properties 
String url = "jdbc:presto://example.net:8080/hive/sales?user=test&password=secret&SSL=true"; 
Connection connection = DriverManager.getConnection(url); 

我希望你知道如何使用Java中的正常數據庫執行SQL語句。如果不是看到https://docs.oracle.com/javase/tutorial/jdbc/basics/processingsqlstatements.html

從本質上講,

Statement stmt = null; 
String query = "select COF_NAME, SUP_ID, PRICE, " + 
       "SALES, TOTAL " + 
       "from " + dbName + ".COFFEES"; 
try { 
    stmt = con.createStatement(); 
    ResultSet rs = stmt.executeQuery(query); 
    while (rs.next()) { 
     String coffeeName = rs.getString("COF_NAME"); 
     int supplierID = rs.getInt("SUP_ID"); 
     float price = rs.getFloat("PRICE"); 
     int sales = rs.getInt("SALES"); 
     int total = rs.getInt("TOTAL"); 
     System.out.println(coffeeName + "\t" + supplierID + 
          "\t" + price + "\t" + sales + 
          "\t" + total); 
    } 
} catch (SQLException e) { 
    JDBCTutorialUtilities.printSQLException(e); 
} finally { 
    if (stmt != null) { stmt.close(); } 
} 

至於搞清楚正確的連接參數(在第一個例子JDBC URL)爲您的環境,請參考第Qubole你友好的技術支持。