我对HBase开发很新。我关注link。 我正在使用Hbase-1.1.2版本。当我使用示例代码时,我收到警告。有几种方法被弃用(例如,新的HBaseAdmin(conf);)我看到HBaseAdmin类有3个构造函数。 3个构造函数中有2个已被弃用。只有一个构造函数接受" ClusterConnection"作为一个论点。我不知道我正在按照正确的链接玩HBase。请问请使用最新的hbase库提供示例。我将HBase作为独立模式运行。
答案 0 :(得分:4)
这应该有帮助
HConnection connection;
HTableInterface hTableInterface = null;
Configuration hBaseConfig = HBaseConfiguration.create();
hBaseConfig.setInt("timeout", 120000);
//zookeeper quorum, basic info needed to proceed
hBaseConfig.set("hbase.zookeeper.quorum","host1, host2, host3");
hBaseConfig.set("hbase.zookeeper.property.clientPort", "2181");
hBaseConfig.set("zookeeper.znode.parent", "/hbase-unsecure");
connection = HConnectionManager.createConnection(hBaseConfig);
hTableInterface = connection.getTable(TableName.valueOf("amarTest"));
try {
Put put = new Put(Bytes.toBytes("999"));
put.add(Bytes.toBytes("cf"),Bytes.toBytes("name"), Bytes.toBytes("amar"));
hTableInterface.put(put);
System.out.println("done");
} catch (Exception e) {
e.printStackTrace();
} finally {
hTableInterface.close();
connection.close();
}
答案 1 :(得分:0)
这是一个简单的例子:
public void setUp() throws Exception {
try {
Configuration hBaseConfig = HBaseConfiguration.create();
Connection connection = ConnectionFactory.createConnection(hBaseConfig);
table = connection.getTable(TableName.valueOf("books"));
} catch (Throwable t) {
t.printStackTrace();
}
}
来源:http://apisonar.com/java-examples/org.apache.hadoop.hbase.HBaseConfiguration.create.html#Example-9