本帖最后由 墨默滴 于 2016-6-21 15:21 编辑
hbase 1.14 hbase(main):002:0> scan 'test'
ROW COLUMN+CELL
row1 column=cf:a, timestamp=1461726446872, value=value1
row2 column=cf:b, timestamp=1461726455672, value=value2
row3 column=cf:c, timestamp=1461726464420, value=value3
3 row(s) in 0.2160 seconds
IDEA读取数据读不到,也写不进去,创建表可以
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.*;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;
public class HBaseTestCase {
public static void createSchemaTables(Configuration cfg) throws IOException {
try{
Connection connection = ConnectionFactory.createConnection(cfg);
Table table = connection.getTable(TableName.valueOf("test"));
System.out.print(table.toString());
// Put put = new Put(Bytes.toBytes("row4"));
// table.put(put);
Get g=new Get(Bytes.toBytes("row1"));
try {
Result result = table.get(g);
System.out.print(result);
} finally {
table.close();
connection.close();
}
}catch (MasterNotRunningException e) {
e.printStackTrace();
} catch (ZooKeeperConnectionException e) {
e.printStackTrace();
}
}
public static void main(String [] args) throws IOException {
Configuration conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum", "172.16.0.30");
conf.set("hbase.zookeeper.property.clientPort", "2181");
try {
createSchemaTables(conf);
} catch (Exception e) {
e.printStackTrace();
}
}
}
|
|