HBase APIs for Java hello world
This example is a "hello world" application, using the Bigtable HBase client library for Java, that illustrates how to:
- Set up authentication
- Connect to a Bigtable instance.
- Create a new table.
- Write data to the table.
- Read the data back.
- Delete the table.
Set up authentication
To use the Java samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
For more information, see Set up authentication for a local development environment.
Running the sample
The sample uses the HBase APIs to communicate with
Bigtable. The code for this sample is in the GitHub repository
GoogleCloudPlatform/cloud-bigtable-examples, in the directory
java/hello-world
.
To run this sample program, follow the instructions for the sample on GitHub.
Using the HBase APIs
The sample application connects to Bigtable and demonstrates some simple operations.
Installing and importing the client library
This sample uses the Bigtable HBase client for Java, as well as Maven. See the instructions for using the client library.
The sample uses the following imports:
Connecting to Bigtable
Connect to Bigtable using the BigtableConfiguration
class.
Creating a table
Use the Admin API to create a table.
Writing rows to a table
Use the Table
class to put rows to the table. For better throughput, consider
using the BigtableBufferedMutator
class.
Reading a row by its key
Get a row directly using its key.
Scanning all table rows
Use the Scan
class to get a range of rows.
Deleting a table
Delete a table using the Admin API.
Putting it all together
Here is the full example without comments.