Guida rapida di Bigtable (HBase)
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Guida rapida per Cloud Bigtable che mostra la connessione a un'istanza e la lettura di una riga da una tabella.
Per saperne di più
Per la documentazione dettagliata che include questo esempio di codice, vedi quanto segue:
Esempio di codice
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","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)."]]