google-big-queryHow do I use Google Big Query JDBC to access data?
Google BigQuery provides a JDBC driver for connecting to BigQuery from Java applications. This driver is available as a part of the Google Cloud SDK.
To use the driver, add the following code to your application:
Class.forName("com.google.cloud.sql.Driver");
Connection connection = DriverManager.getConnection(
"jdbc:google:bigquery://<project-id>:<dataset-id>");
The code above creates a connection to a BigQuery project and dataset.
You can then use the connection to execute queries and retrieve the results. For example, the following code will retrieve the number of rows in a table:
String query = "SELECT COUNT(*) FROM <table-name>";
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(query);
while (resultSet.next()) {
System.out.println(resultSet.getLong(1));
}
The output of the code above would be a single number representing the number of rows in the table.
Helpful links
More of Google Big Query
- How can I use Google Big Query to analyze Reddit data?
- How do I use the "not in" operator in Google BigQuery?
- How can I compare Google BigQuery and AWS Redshift for software development?
- How can I get started with Google BigQuery training?
- How can I use Google Big Query for specific use cases?
- How do I use an IF statement in Google BigQuery?
- How do I set up a Google Big Query zone?
- How can I use Google Big Query to count the number of zeros in a given dataset?
- ¿Cuáles son las ventajas y desventajas de usar Google BigQuery?
- How do I use the YEAR function in Google BigQuery?
See more codes...