美文网首页
presto jdbc java

presto jdbc java

作者: zhuchunyan_aiji | 来源:发表于2020-11-05 20:35 被阅读0次

    <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();

    相关文章

      网友评论

          本文标题:presto jdbc java

          本文链接:https://www.haomeiwen.com/subject/gjiavktx.html