Bigtable - Schnellstart (HBase)
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Schnellstart für Cloud Bigtable, das zeigt, wie eine Verbindung zu einer Instanz hergestellt und eine Zeile aus einer Tabelle gelesen wird.
Weitere Informationen
Eine ausführliche Dokumentation, die dieses Codebeispiel enthält, finden Sie hier:
Codebeispiel
Nächste Schritte
Wenn Sie nach Codebeispielen für andere Google Cloud -Produkte suchen und filtern möchten, können Sie den Google Cloud -Beispielbrowser verwenden.
Sofern nicht anders angegeben, sind die Inhalte dieser Seite unter der Creative Commons Attribution 4.0 License und Codebeispiele unter der Apache 2.0 License lizenziert. Weitere Informationen finden Sie in den Websiterichtlinien von Google Developers. Java ist eine eingetragene Marke von Oracle und/oder seinen Partnern.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis quickstart demonstrates how to connect to a Cloud Bigtable instance using the native HBase API.\u003c/p\u003e\n"],["\u003cp\u003eThe code sample shows how to read a specific row from an existing table within the Bigtable instance.\u003c/p\u003e\n"],["\u003cp\u003eThe example requires setting up Application Default Credentials for authentication with Bigtable.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code is written in Java and utilizes the Bigtable client library.\u003c/p\u003e\n"],["\u003cp\u003eTo find code samples for other Google Cloud products, the Google Cloud sample browser is recommended for searching and filtering.\u003c/p\u003e\n"]]],[],null,["Quickstart for Cloud Bigtable which shows connecting to an instance and reading a row from a table.\n\nExplore further\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Bigtable client libraries](/bigtable/docs/reference/libraries)\n\nCode sample \n\nJava\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n\n package com.example.cloud.bigtable.quickstart;\n\n import com.google.cloud.bigtable.hbase.BigtableConfiguration;\n\n import java.io.IOException;\n import org.apache.hadoop.hbase.TableName;\n import org.apache.hadoop.hbase.client.Connection;\n import org.apache.hadoop.hbase.client.Get;\n import org.apache.hadoop.hbase.client.Result;\n import org.apache.hadoop.hbase.client.Table;\n import org.apache.hadoop.hbase.util.Bytes;\n\n /**\n * A quickstart application that shows connecting to a Cloud Bigtable instance\n * using the native HBase API to read a row from a table.\n */\n public class Quickstart {\n\n public static void main(String... args) {\n\n String projectId = args[0]; // my-gcp-project-id\n String instanceId = args[1]; // my-bigtable-instance-id\n String tableId = args[2]; // my-bigtable-table-id\n\n // Create a connection to the Cloud Bigtable instance.\n // Use try-with-resources to make sure the connection is closed correctly\n try (Connection connection = BigtableConfiguration.connect(projectId, instanceId)) {\n\n System.out.println(\"--- Connection established with Bigtable Instance ---\");\n // Create a connection to the table that already exists\n // Use try-with-resources to make sure the connection to the table is closed correctly\n try (Table table = connection.getTable(TableName.valueOf(tableId))) {\n\n // Read a row\n String rowKey = \"r1\";\n System.out.printf(\"--- Reading for row-key: %s for provided table: %s ---\\n\",\n rowKey, tableId);\n\n // Retrieve the result\n Result result = table.get(new Get(Bytes.toBytes(rowKey)));\n\n // Convert row data to string\n String rowValue = Bytes.toString(result.value());\n\n System.out.printf(\"Scanned value for Row r1: %s \\n\", rowValue);\n\n System.out.println(\" --- Finished reading row --- \");\n\n } catch (IOException e) {\n // handle exception while connecting to a table\n throw e;\n }\n } catch (IOException e) {\n System.err.println(\"Exception while running quickstart: \" + e.getMessage());\n e.printStackTrace();\n }\n }\n }\n\nWhat's next\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=bigtable)."]]