我使用的Presto在Qubole数据服务上天青。我想从 Java 程序执行 Presto 查询。如何从 Java 程序在 Azure 上的 Qubole 数据服务上的 Presto 集群中执行查询?
Presto 提供了一个普通的 JDBC 驱动程序,允许您运行 SQL 查询。您所要做的就是将它包含在您的 Java 应用程序中。在他们的网站https://prestodb.io/docs/current/installation/jdbc.html上有一个关于如何连接到 Presto 集群的示例:
// 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);
Run Code Online (Sandbox Code Playgroud)
我希望您知道如何使用 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(); }
}
Run Code Online (Sandbox Code Playgroud)
至于为您的环境找出正确的连接参数(第一个示例中的 jdbc url),请参考您在 Qubole 的友好技术支持。
| 归档时间: |
|
| 查看次数: |
4750 次 |
| 最近记录: |