2012-08-23 46 views
0

卡桑德拉-節儉1.1.2.jarApache的節儉呼叫卡桑德拉插入在 「鑰匙」

問題代碼垃圾/空值:

 
      ColumnOrSuperColumn cosc = null; 
     org.apache.cassandra.thrift.Column c = new org.apache.cassandra.thrift.Column(); 
     c.setName ("full_name".getBytes ("UTF-8")); 
     c.setValue ("Test name".getBytes ("UTF-8")); 
     c.setTimestamp (System.currentTimeMillis()); 

     // insert data 
//  long timestamp = System.currentTimeMillis(); 

     try { 
      client.set_keyspace("CClient"); 

      bb=ByteBuffer.allocate (10); 
      client.insert (bb.putInt(1), 
          new ColumnParent ("users"), 
          c, 
          ConsistencyLevel.QUORUM); 
      bb.putInt (2); 
      cosc = client.get (bb, cp, ConsistencyLevel.QUORUM); 
     } 
     catch (TimedOutException toe) { 
      System.out.println (toe.getMessage()); 
     } 
     catch (org.apache.cassandra.thrift.UnavailableException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
     catch (Exception e) { 
      e.printStackTrace(); 
     } 
     finally { 
      System.out.println (new String (cosc.getColumn().getName()) + "-" + new String (cosc.getColumn().getValue())); 
     } 

上面顯示的代碼在數據庫中插入了一些垃圾或null,我不明白爲什麼?

看看它是如何看起來對CLI:

 
RowKey: 
=> (column=full_name, value=Test name, timestamp=1345743985973) 

在任何幫助,這是極大的讚賞。

謝謝。

+2

我並不真正關注你的問題,但如果你使用像Hector這樣的客戶端庫而不是使用原始的節儉,它會容易得多。 – sbridges

+1

@sbridges你應該讓這個答案,因爲這是正確的答案。 –

+0

我查找了Hector的源代碼,以瞭解如何完成插入操作,並且ByteBufferUtil就是其中之一。 (1), 新的ColumnParent(「用戶」), c, ConsistencyLevel.QUORUM); ' –

回答

0

您正在使用行鍵創建一行作爲字節。 在Cassandra cli中,如果將行列爲字節,您可能會看到行鍵。 例如在cassandra cli中輸入:
假定用戶密鑰爲字節;
列表用戶;