我在Azure上使用Qubole数据服务中的Presto。我想从Java程序执行Presto查询。如何在Java程序的Azure上的Qubole数据服务上执行查询?
presto提供普通的JDBC驱动程序,可让您运行SQL查询。您要做的就是将其包括在Java应用程序中。有一个有关如何连接到其网站上的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);
我希望您知道如何使用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的友好技术支持。