2017-12-18 409 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你友好的技术支持。