// 查看数据表ob_table
》 describe‘ob_table’

5.3 测试
// 在eclipse项目中编写一个客户端,向数据表ob_table中插入测试数据
〔java〕 view plain copypackage com.hbase.demo.observer;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;
public class Test {
public static void main(String〔〕 args) throws IOException {
// 配置HBse
Configuration conf = HBaseConfiguration.create();
conf.set(“hbase.zookeeper.quorum”, “localhost”);
conf.set(“hbase.zookeeper.property.clientPort”, “2222”);
// 建立一个的连接
Connection conn = ConnectionFactory.createConnection(conf);
// 获取表
HTable table = (HTable) conn.getTable(TableName.valueOf(“ob_table”));
// 插入测试数据
Put put = new Put(Bytes.toBytes(“rowkey01”));
put.addColumn(Bytes.toBytes(“info”), Bytes.toBytes(“name”), Bytes.toBytes(“carl”));
put.addColumn(Bytes.toBytes(“info”), Bytes.toBytes(“score”), Bytes.toBytes(“92”));
table.put(put);
// 关闭资源
table.close();
conn.close();
}
}
// 插入数据后,在hbase shell中查看数据表ob_table中的数据
$hbase shell
》 scan‘ob_table’

//在hbase shell中查看二级索引表index_ob_table中的数据
》 scan‘index_ob_table’
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-59353-9.html
而它常常借智慧而支持