2011-04-18 139 views
1

我想要一個非常簡單的例子卡桑德拉。 我存儲在數據庫卡桑德拉一個列族:卡桑德拉找回整行

[[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,我已經得到了整個行內的一切。我的問題是我怎麼才能得到沒有名稱和時間戳部分的價值?非常感謝。

回答

2

使用以下方式獲取每列。我使得方法得到的值如下:

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 { 

      } 
     } 
+0

它的工作原理就像一個魅力。非常感謝。 :-) – Lucas 2011-04-18 04:59:18