2010-01-25 45 views
-2

我想在Google大表格中使用java和servelt代碼創建表格? 如何創建表並插入Google大表數據庫? 我想樣品編碼在谷歌大表中創建表?如何在Google Bigtable中創建表格

+0

「我想」 沒有得到:) – MarkR 2010-01-26 08:34:37

回答

1

六年後,現在可以。看看這個快速入門頁面,瞭解如何獲取Bigtable實例並開始寫入它 https://cloud.google.com/bigtable/docs/quickstart

然後這裏是一個示例「Hello,World!」應用 https://cloud.google.com/bigtable/docs/samples-java-hello

例如

try (Connection connection = BigtableConfiguration.connect(projectId, instanceId)) { 

     Admin admin = connection.getAdmin(); 

     HTableDescriptor descriptor = new HTableDescriptor(TableName.valueOf(TABLE_NAME)); 
     descriptor.addFamily(new HColumnDescriptor(COLUMN_FAMILY_NAME)); 

     print("Create table " + descriptor.getNameAsString()); 
     admin.createTable(descriptor); 

     Table table = connection.getTable(TableName.valueOf(TABLE_NAME)); 

     print("Write some greetings to the table"); 
     for (int i = 0; i < GREETINGS.length; i++) { 
     String rowKey = "greeting" + i; 

     Put put = new Put(Bytes.toBytes(rowKey)); 
     put.addColumn(COLUMN_FAMILY_NAME, COLUMN_NAME, Bytes.toBytes(GREETINGS[i])); 
     table.put(put); 
     } 

     String rowKey = "greeting0"; 
     Result getResult = table.get(new Get(Bytes.toBytes(rowKey))); 
}