我有用户名和密码作为ColumnFamily的列与username键。
create column family TestUserInfo with comparator = UTF8Type withcolumn_metadata = [{column_name: username, validation_class:UTF8Type},{column_name: password, validation_class:UTF8Type}];
当键存在于db中时,下面的代码可以正常工作。然而当Key不存在时抛出 me.prettyprint.hector.api.exceptions.HInvalidRequestException: InvalidRequestException(为什么:Key可能不是空的)
SliceQuery<String, String, String> sliceQuery = HFactory.createSliceQuery(cassandraDBObject.getKeyspace(), StringSerializer.get(), StringSerializer.get(), StringSerializer.get());
sliceQuery.setColumnFamily("TestUserInfo");
sliceQuery.setKey(userName);
sliceQuery.setColumnNames("username", "password");
String userNameFromDB = null;
String passwordFromDB = null;
try {
[Error here -->] QueryResult<ColumnSlice<String, String>> queryResult = sliceQuery.execute();
ColumnSlice<String, String> resultCol = queryResult.get();
System.out.println(resultCol);
userNameFromDB = resultCol.getColumnByName("username").getValue();
passwordFromDB = resultCol.getColumnByName("password").getValue();
} catch (Exception e) {
e.printStackTrace();
}
你能告诉我我哪里做错了吗?或者这是预期的行为?如果是这样,那么我如何检查空结果?说我正在检查从数据库登录信息。然后,如果用户名(键)不是在数据库那么我需要得到一个空的结果对吗?谢谢!
听起来就像是在抱怨你给它一个空的userName