Bigtable 快速入门 (HBase)
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Cloud Bigtable 快速入门:显示如何连接到实例以及如何从表中读取行。
深入探索
如需查看包含此代码示例的详细文档,请参阅以下内容:
代码示例
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。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)."]]