presto jdbc java

2020-11-05  本文已影响0人  zhuchunyan_aiji

<dependency>
<groupId>com.facebook.presto</groupId>
<artifactId>presto-jdbc</artifactId>
<version>0.242.1</version>
</dependency>

jdbc:presto://host:port
jdbc:presto://host:port/catalog
jdbc:presto://host:port/catalog/schema

// 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
Class.forName("com.facebook.presto.jdbc.PrestoDriver");
String url = "jdbc:presto://example.net:8080/hive/sales?user=test&password=secret&SSL=true";
Connection connection = DriverManager.getConnection(url);

statement = connection.createStatement();
String sql;
sql = "select auth_id, auth_name from mysql.tutorials.author”;
ResultSet resultSet = statement.executeQuery(sql);
while(resultSet.next()){
int id = resultSet.getInt("auth_id");
String name = resultSet.getString(“auth_name");
System.out.print("ID: " + id + ";\nName: " + name + "\n");
}

List<JSONObject> results = new ArrayList<>();
int count = resultSet.getMetaData().getColumnCount();
String[] columns = new String[count];
for (int i = 0; i < count; i++) {
columns[i] = resultSet.getMetaData().getColumnName(i + 1);
}
while (resultSet.next()) {
JSONObject jsonObject = new JSONObject();
for (int j = 0; j < count; j++) {
jsonObject.put(columns[j], resultSet.getString(j + 1));
}
results.add(jsonObject);
}
resultSet.close();
statement.close();
connection.close();

上一篇下一篇

猜你喜欢

热点阅读