我创建了一个java应用程序来读取HBase中的数据。我检查了link1link2link3和link4。即使我的表中有数据,程序也会返回null。HBase读取数据返回null
HBase的外壳:
hbase(main):009:0> get 'login','1'
COLUMN CELL
password: password timestamp=1456588594424, value=hpassword
username: username timestamp=1456588582413, value=husername
2 row(s) in 0.0120 seconds
代码:
Configuration config = HBaseConfiguration.create();
HTable table = new HTable(config, "login");
Get g = new Get(Bytes.toBytes("row1"));
Result r = table.get(g);
byte [] value = r.getValue(Bytes.toBytes("username"),Bytes.toBytes("username"));
byte [] value1 = r.getValue(Bytes.toBytes("password"),Bytes.toBytes("password"));
String valueStr = Bytes.toString(value);
String valueStr1 = Bytes.toString(value1);
System.out.println("username: "+ valueStr+"\npassword: "+valueStr1);
Scan s = new Scan();
s.addColumn(Bytes.toBytes("username"), Bytes.toBytes("username"));
s.addColumn(Bytes.toBytes("password"), Bytes.toBytes("password"));
ResultScanner scanner = table.getScanner(s);
try
{
for (Result rnext = scanner.next(); rnext != null; rnext = scanner.next())
{
System.out.println("Found row : " + rnext);
}
}finally{
scanner.close();
}
输出:
username: null
password: null
我失去了一些东西,或者我需要在代码编辑的地方?
此外,我需要将其实现到Java Play Framework中。你有什么想法吗?
在此先感谢。
目前还不清楚哪些列族用于存储数据。你使用“用户名”列和列家庭,它似乎是错误的 – AdamSkywalker
谢谢你的帮助。我改变了它们,并将Bytes.toBytes(“row1”))“row1”更改为“1”。 –
为什么你使用扫描并在同一时间? –