add explicit example for jdbc query context on connection properties (#10182)

* add explicit example for jdbc query context on connection properties

* make comment clearer

* Update sql.md

* Update sql.md
This commit is contained in:
Clint Wylie 2020-07-24 13:43:04 -07:00 committed by GitHub
parent 6d8799f2df
commit 79dffefbf8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 4 deletions

View File

@ -829,9 +829,7 @@ delivered due to an error.
### JDBC ### JDBC
You can make Druid SQL queries using the [Avatica JDBC driver](https://calcite.apache.org/avatica/downloads/). Once You can make Druid SQL queries using the [Avatica JDBC driver](https://calcite.apache.org/avatica/downloads/). We recommend using Avatica JDBC driver version 1.17.0 or later. Note that as of the time of this writing, Avatica 1.17.0, the latest version, does not support passing connection string parameters from the URL to Druid, so you must pass them using a `Properties` object. Once you've downloaded the Avatica client jar, add it to your classpath and use the connect string `jdbc:avatica:remote:url=http://BROKER:8082/druid/v2/sql/avatica/`.
you've downloaded the Avatica client jar, add it to your classpath and use the connect string
`jdbc:avatica:remote:url=http://BROKER:8082/druid/v2/sql/avatica/`.
Example code: Example code:
@ -849,7 +847,7 @@ try (Connection connection = DriverManager.getConnection(url, connectionProperti
final ResultSet resultSet = statement.executeQuery(query) final ResultSet resultSet = statement.executeQuery(query)
) { ) {
while (resultSet.next()) { while (resultSet.next()) {
// Do something // process result set
} }
} }
} }
@ -885,6 +883,19 @@ Druid SQL supports setting connection parameters on the client. The parameters i
All other context parameters you provide will be attached to Druid queries and can affect how they run. See All other context parameters you provide will be attached to Druid queries and can affect how they run. See
[Query context](query-context.html) for details on the possible options. [Query context](query-context.html) for details on the possible options.
```java
String url = "jdbc:avatica:remote:url=http://localhost:8082/druid/v2/sql/avatica/";
// Set any query context parameters you need here.
Properties connectionProperties = new Properties();
connectionProperties.setProperty("sqlTimeZone", "America/Los_Angeles");
connectionProperties.setProperty("useCache", "false");
try (Connection connection = DriverManager.getConnection(url, connectionProperties)) {
// create and execute statements, process result sets, etc
}
```
Note that to specify an unique identifier for SQL query, use `sqlQueryId` instead of `queryId`. Setting `queryId` for a SQL Note that to specify an unique identifier for SQL query, use `sqlQueryId` instead of `queryId`. Setting `queryId` for a SQL
request has no effect, all native queries underlying SQL will use auto-generated queryId. request has no effect, all native queries underlying SQL will use auto-generated queryId.