Access Druid database via JDBC

The Druid database can be accessed via JDBC. To do so, it is recommended to use Avatica JDBC driver. We then use the connect string jdbc:avatica:remote:url=https://<Mining Platform Data URL>/druid/v2/sql/avatica/.

Please note that JDBC uses Java. Thus, we can use the subsequent code to connect to Druid:

// Connect to /druid/v2/sql/avatica/ on your Broker.
String url = "jdbc:avatica:remote:url=https://<Mining Platform Data URL>/druid/v2/sql/avatica/";

// Set any connection context parameters you need here
// Or leave empty for default behavior.
Properties connectionProperties = new Properties();

try (Connection connection = DriverManager.getConnection(url, connectionProperties)) {
  try (
      final Statement statement = connection.createStatement();
      final ResultSet resultSet = statement.executeQuery(query)
  ) {
    while (resultSet.next()) {
      // process result set
    }
  }
}