我正在使用 Java Hector API 从 Cassandra 数据库中检索数据,如下所示:
public static void retrieveData() {
try {
//Create a cluster object from your existing Cassandra cluster
Cluster cluster = HFactory.getOrCreateCluster("Test Cluster", "localhost:9160");
//Create a keyspace object from the existing keyspace we created using CLI
Keyspace keyspace = HFactory.createKeyspace("TestDB", cluster);
SliceQuery<String, String, String> sliceQuery = HFactory.createSliceQuery(keyspace, stringSerializer, stringSerializer, stringSerializer);
sliceQuery.setColumnFamily("ClientHeaders").setKey("1234");
sliceQuery.setRange("", "", false, 10);
sliceQuery.setColumnNames("ip_address","uuid");
QueryResult<ColumnSlice<String, String>> result = sliceQuery.execute();
System.out.println("\nInserted data is as follows:\n" + result.get());
} catch (Exception ex) {
System.out.println("Error encountered while retrieving data!!");
ex.printStackTrace() ;
}
因此,我按以下顺序根据查询获取检索到的值:
ColumnSlice([HColumn(ip_address=203.110.85.171), HColumn(uuid=a3363400-abfd-0130-e2cf-07b5c765964c)])
但是我想在一些字符串变量(字符串 ip=ip_address 等)中提取结果并使用。但我不知道该怎么做?请帮忙。谢谢。