Bigtable クイックスタート(HBase)
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
インスタンスへの接続とテーブルから行の読み取りを示す Cloud Bigtable のクイックスタート
もっと見る
このコードサンプルを含む詳細なドキュメントについては、以下をご覧ください。
コードサンプル
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","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)."]]