public void runQueryWithNamedParameters() throws InterruptedException {
    // [START bigquery_query_params_named]
    // BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
    String corpus = "romeoandjuliet";
    long minWordCount = 250;
    String query =
        "SELECT word, word_count\n"
            + "FROM `bigquery-public-data.samples.shakespeare`\n"
            + "WHERE corpus = @corpus\n"
            + "AND word_count >= @min_word_count\n"
            + "ORDER BY word_count DESC";
    // Note: Standard SQL is required to use query parameters.
    QueryJobConfiguration queryConfig =
        QueryJobConfiguration.newBuilder(query)
            .addNamedParameter("corpus", QueryParameterValue.string(corpus))
            .addNamedParameter("min_word_count", QueryParameterValue.int64(minWordCount))
            .build();

    // Print the results.
    for (FieldValueList row : bigquery.query(queryConfig).iterateAll()) {
      for (FieldValue val : row) {
        System.out.printf("%s,", val.toString());
      }
      System.out.printf("\n");
    }
    // [END bigquery_query_params_named]
  }
public void runQueryWithNamedParameters ( ) throws InterruptedException { String corpus = "romeoandjuliet" ; long minWordCount = 250 ; String query = "SELECT word, word_count\n" + "FROM `bigquery-public-data.samples.shakespeare`\n" + "WHERE corpus = @corpus\n" + "AND word_count >= @min_word_count\n" + "ORDER BY word_count DESC" ; QueryJobConfiguration queryConfig = QueryJobConfiguration . newBuilder ( query ) . addNamedParameter ( "corpus" , QueryParameterValue . string ( corpus ) ) . addNamedParameter ( "min_word_count" , QueryParameterValue . int64 ( minWordCount ) ) . build ( ) ; for ( FieldValueList row : bigquery . query ( queryConfig ) . iterateAll ( ) ) { for ( FieldValue val : row ) { System . out . printf ( "%s," , val . toString ( ) ) ; } System . out . printf ( "\n" ) ; } }
Example of running a query with named query parameters.