卡桑德拉找回整行
问题描述:
我想要一个非常简单的例子卡桑德拉。 我存储在数据库卡桑德拉一个列族:卡桑德拉找回整行
[[email protected]] list Hotel;
Using default limit of 100
-------------------
RowKey: AZS_011
=> (column=name, value=43616d6272696120537569746573, timestamp=527682928555011)
值以上其实是“坎布里亚套房”。当我使用下面的代码从数据库中检索值:
String key = "AZS_011";
Connector connector = new Connector();
Cassandra.Client client = connector.connect();
ColumnPath cp = new ColumnPath("Hotel");
cp.setColumn(to_bb("name"));
ColumnOrSuperColumn col = client.get(to_bb(key), cp, CL);
String hotel_name = new String(col.column.value.array(), UTF8);
System.out.println("I found: " + hotel_name);
connector.close();
我最终输出: 我发现:getnameCambria套房 14 B
看来,通过参考col.column.value,我已经得到了整个行内的一切。我的问题是我怎么才能得到没有名称和时间戳部分的价值?非常感谢。
答
使用以下方式获取每列。我使得方法得到的值如下:
for (ColumnOrSuperColumn c : result) {
if (c.getColumn() != null) {
String name = new String(c.getColumn().getName(), ENCODING);
String value = new String(c.getColumn().getValue(), ENCODING);
long timestamp = c.getColumn().getTimestamp();
System.out.println(" name: '" + name + "', value: '" + value + "', timestamp: " + timestamp);
} else {
}
}
它的工作原理就像一个魅力。非常感谢。 :-) – Lucas 2011-04-18 04:59:18