public interface Connection
A Connection is a session between a Java application and BigQuery. SQL statements are executed and results are returned within the context of a connection.
Methods
close()
public abstract boolean close()
Sends a query cancel request. This call will return immediately
Type | Description |
boolean |
Type | Description |
BigQuerySQLException |
dryRun(String sql)
public abstract BigQueryDryRunResult dryRun(String sql)
Execute a query dry run that returns information on the schema and query parameters of the query results.
Name | Description |
sql | String typically a static SQL SELECT statement |
Type | Description |
BigQueryDryRunResult |
Type | Description |
BigQuerySQLException |
executeSelect(String sql)
public abstract BigQueryResult executeSelect(String sql)
Execute a SQL statement that returns a single ResultSet.
Example of running a query.
{
@code
ConnectionSettings connectionSettings =
ConnectionSettings.newBuilder()
.setRequestTimeout(10L)
.setMaxResults(100L)
.setUseQueryCache(true)
.build();
Connection connection = bigquery.createConnection(connectionSettings);
String selectQuery = "SELECT corpus FROM bigquery-public-data.samples.shakespeare
GROUP BY corpus;";
BigQueryResult bqResultSet = connection.executeSelect(selectQuery)
ResultSet rs = bqResultSet.getResultSet();
while (rs.next()) {
System.out.printf("%s,", rs.getString("corpus"));
}
Name | Description |
sql | String a static SQL SELECT statement |
Type | Description |
BigQueryResult | a ResultSet that contains the data produced by the query |
Type | Description |
BigQuerySQLException |
executeSelect(String sql, List<Parameter> parameters, Map<String,String>[] labels)
public abstract BigQueryResult executeSelect(String sql, List<Parameter> parameters, Map<String,String>[] labels)
This method executes a SQL SELECT query
Name | Description |
sql | String SQL SELECT query |
parameters | List<Parameter> named or positional parameters. The set of query parameters must either be all positional or all named parameters. |
labels | Map<String,String>[] (optional) the labels associated with this query. You can use these to organize and group your query jobs. Label keys and values can be no longer than 63 characters, can only contain lowercase letters, numeric characters, underscores and dashes. International characters are allowed. Label values are optional and Label is a Varargs. You should pass all the Labels in a single Map .Label keys must start with a letter and each label in the list must have a different key. |
Type | Description |
BigQueryResult | BigQueryResult containing the output of the query |
Type | Description |
BigQuerySQLException |