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()
publicabstractbooleanclose()
Sends a query cancel request. This call will return immediately
(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.
(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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Interface Connection (2.54.1)\n\nVersion latestkeyboard_arrow_down\n\n- [2.54.1 (latest)](/java/docs/reference/google-cloud-bigquery/latest/com.google.cloud.bigquery.Connection)\n- [2.54.0](/java/docs/reference/google-cloud-bigquery/2.54.0/com.google.cloud.bigquery.Connection)\n- [2.53.0](/java/docs/reference/google-cloud-bigquery/2.53.0/com.google.cloud.bigquery.Connection)\n- [2.52.0](/java/docs/reference/google-cloud-bigquery/2.52.0/com.google.cloud.bigquery.Connection)\n- [2.51.0](/java/docs/reference/google-cloud-bigquery/2.51.0/com.google.cloud.bigquery.Connection)\n- [2.50.1](/java/docs/reference/google-cloud-bigquery/2.50.1/com.google.cloud.bigquery.Connection)\n- [2.49.0](/java/docs/reference/google-cloud-bigquery/2.49.0/com.google.cloud.bigquery.Connection)\n- [2.48.1](/java/docs/reference/google-cloud-bigquery/2.48.1/com.google.cloud.bigquery.Connection)\n- [2.47.0](/java/docs/reference/google-cloud-bigquery/2.47.0/com.google.cloud.bigquery.Connection)\n- [2.46.0](/java/docs/reference/google-cloud-bigquery/2.46.0/com.google.cloud.bigquery.Connection)\n- [2.45.0](/java/docs/reference/google-cloud-bigquery/2.45.0/com.google.cloud.bigquery.Connection)\n- [2.44.0](/java/docs/reference/google-cloud-bigquery/2.44.0/com.google.cloud.bigquery.Connection)\n- [2.43.3](/java/docs/reference/google-cloud-bigquery/2.43.3/com.google.cloud.bigquery.Connection)\n- [2.42.3](/java/docs/reference/google-cloud-bigquery/2.42.3/com.google.cloud.bigquery.Connection)\n- [2.41.0](/java/docs/reference/google-cloud-bigquery/2.41.0/com.google.cloud.bigquery.Connection)\n- [2.40.3](/java/docs/reference/google-cloud-bigquery/2.40.3/com.google.cloud.bigquery.Connection)\n- [2.39.1](/java/docs/reference/google-cloud-bigquery/2.39.1/com.google.cloud.bigquery.Connection)\n- [2.38.2](/java/docs/reference/google-cloud-bigquery/2.38.2/com.google.cloud.bigquery.Connection)\n- [2.37.2](/java/docs/reference/google-cloud-bigquery/2.37.2/com.google.cloud.bigquery.Connection)\n- [2.36.0](/java/docs/reference/google-cloud-bigquery/2.36.0/com.google.cloud.bigquery.Connection)\n- [2.35.0](/java/docs/reference/google-cloud-bigquery/2.35.0/com.google.cloud.bigquery.Connection)\n- [2.34.2](/java/docs/reference/google-cloud-bigquery/2.34.2/com.google.cloud.bigquery.Connection)\n- [2.33.2](/java/docs/reference/google-cloud-bigquery/2.33.2/com.google.cloud.bigquery.Connection) \n\n public interface Connection\n\nA Connection is a session between a Java application and BigQuery. SQL statements are executed\nand results are returned within the context of a connection.\n\nMethods\n-------\n\n### close()\n\n public abstract boolean close()\n\n| **Beta**\n|\n| This feature is covered by the [Pre-GA Offerings Terms](/terms/service-terms#1) of the Terms of Service. Pre-GA libraries might have limited support, and changes to pre-GA libraries might not be compatible with other pre-GA versions. For more information, see the launch stage descriptions.\n\nSends a query cancel request. This call will return immediately\n\n### dryRun(String sql)\n\n public abstract BigQueryDryRunResult dryRun(String sql)\n\n| **Beta**\n|\n| This feature is covered by the [Pre-GA Offerings Terms](/terms/service-terms#1) of the Terms of Service. Pre-GA libraries might have limited support, and changes to pre-GA libraries might not be compatible with other pre-GA versions. For more information, see the launch stage descriptions.\n\nExecute a query dry run that returns information on the schema and query parameters of the\nquery results.\n\n### executeSelect(String sql)\n\n public abstract BigQueryResult executeSelect(String sql)\n\n| **Beta**\n|\n| This feature is covered by the [Pre-GA Offerings Terms](/terms/service-terms#1) of the Terms of Service. Pre-GA libraries might have limited support, and changes to pre-GA libraries might not be compatible with other pre-GA versions. For more information, see the launch stage descriptions.\n\nExecute a SQL statement that returns a single ResultSet.\n\nExample of running a query.\n\n{\n@code\nConnectionSettings connectionSettings =\nConnectionSettings.newBuilder()\n.setRequestTimeout(10L)\n.setMaxResults(100L)\n.setUseQueryCache(true)\n.build();\nConnection connection = bigquery.createConnection(connectionSettings);\nString selectQuery = \"SELECT corpus FROM `bigquery-public-data.samples.shakespeare` GROUP BY corpus;\";\nBigQueryResult bqResultSet = connection.executeSelect(selectQuery)\nResultSet rs = bqResultSet.getResultSet();\nwhile (rs.next()) {\nSystem.out.printf(\"%s,\", rs.getString(\"corpus\"));\n}\n\n### executeSelect(String sql, List\\\u003cParameter\\\u003e parameters, Map\\\u003cString,String\\\u003e\\[\\] labels)\n\n public abstract BigQueryResult executeSelect(String sql, List\u003cParameter\u003e parameters, Map\u003cString,String\u003e[] labels)\n\n| **Beta**\n|\n| This feature is covered by the [Pre-GA Offerings Terms](/terms/service-terms#1) of the Terms of Service. Pre-GA libraries might have limited support, and changes to pre-GA libraries might not be compatible with other pre-GA versions. For more information, see the launch stage descriptions.\n\nThis method executes a SQL SELECT query\n\n### executeSelectAsync(String sql)\n\n public abstract ListenableFuture\u003cExecuteSelectResponse\u003e executeSelectAsync(String sql)\n\n| **Beta**\n|\n| This feature is covered by the [Pre-GA Offerings Terms](/terms/service-terms#1) of the Terms of Service. Pre-GA libraries might have limited support, and changes to pre-GA libraries might not be compatible with other pre-GA versions. For more information, see the launch stage descriptions.\n\nExecute a SQL statement that returns a single ResultSet and returns a ListenableFuture to\nprocess the response asynchronously.\n\nExample of running a query.\n\n{\n@code\nConnectionSettings connectionSettings =\nConnectionSettings.newBuilder()\n.setUseReadAPI(true)\n.build();\nConnection connection = bigquery.createConnection(connectionSettings);\nString selectQuery = \"SELECT corpus FROM `bigquery-public-data.samples.shakespeare` GROUP BY corpus;\";\nListenableFuture\\\u003cExecuteSelectResponse\\\u003e executeSelectFuture = connection.executeSelectAsync(selectQuery);\nExecuteSelectResponse executeSelectRes = executeSelectFuture.get();\n\nif(!executeSelectRes.getIsSuccessful()){\nthrow executeSelectRes.getBigQuerySQLException();\n}\n\nBigQueryResult bigQueryResult = executeSelectRes.getBigQueryResult();\nResultSet rs = bigQueryResult.getResultSet();\nwhile (rs.next()) {\nSystem.out.println(rs.getString(1));\n}\n\n### executeSelectAsync(String sql, List\\\u003cParameter\\\u003e parameters, Map\\\u003cString,String\\\u003e\\[\\] labels)\n\n public abstract ListenableFuture\u003cExecuteSelectResponse\u003e executeSelectAsync(String sql, List\u003cParameter\u003e parameters, Map\u003cString,String\u003e[] labels)\n\n| **Beta**\n|\n| This feature is covered by the [Pre-GA Offerings Terms](/terms/service-terms#1) of the Terms of Service. Pre-GA libraries might have limited support, and changes to pre-GA libraries might not be compatible with other pre-GA versions. For more information, see the launch stage descriptions.\n\nExecute a SQL statement that returns a single ResultSet and returns a ListenableFuture to\nprocess the response asynchronously.\n\nExample of running a query.\n\n{\n@code\nConnectionSettings connectionSettings =\nConnectionSettings.newBuilder()\n.setUseReadAPI(true)\n.build();\nConnection connection = bigquery.createConnection(connectionSettings);\nString selectQuery =\n\"SELECT TimestampField, StringField, BooleanField FROM \"\n\n- MY_TABLE\n- \" WHERE StringField = @stringParam\"\n- \" AND IntegerField IN UNNEST(@integerList)\";\n QueryParameterValue stringParameter = QueryParameterValue.string(\"stringValue\");\n QueryParameterValue intArrayParameter =\n QueryParameterValue.array(new Integer\\[\\] {3, 4}, Integer.class);\n Parameter stringParam =\n Parameter.newBuilder().setName(\"stringParam\").setValue(stringParameter).build();\n Parameter intArrayParam =\n Parameter.newBuilder().setName(\"integerList\").setValue(intArrayParameter).build();\n List\\\u003cParameter\\\u003e parameters = ImmutableList.of(stringParam, intArrayParam);\n\n ListenableFuture\\\u003cExecuteSelectResponse\\\u003e executeSelectFut =\n connection.executeSelectAsync(selectQuery, parameters);\n ExecuteSelectResponse executeSelectRes = executeSelectFuture.get();\n\n if(!executeSelectRes.getIsSuccessful()){\n throw executeSelectRes.getBigQuerySQLException();\n }\n\n BigQueryResult bigQueryResult = executeSelectRes.getBigQueryResult();\n ResultSet rs = bigQueryResult.getResultSet();\n while (rs.next()) {\n System.out.println(rs.getString(1));\n }"]]