如果我想通过Netbeans在Sesame存储库中进行SPARQL SELECT查询,我使用以下代码(我在绑定集中得到三个值)。如何进行只返回一个布尔值的ASK查询?
TupleQuery tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
TupleQueryResult result = tupleQuery.evaluate();
List<String> bindingNames = result.getBindingNames();
try {
while (result.hasNext()) {
BindingSet bindingSet = result.next();
Value firstValue1 = bindingSet.getValue(bindingNames.get(0));
Value firstValue2 = bindingSet.getValue(bindingNames.get(1));
Value firstValue3 = bindingSet.getValue(bindingNames.get(2));
}
}
答案 0 :(得分:3)
假设您的con
是RepositoryConnection
,您可以使用prepareBooleanQuery(…)
的某个版本。这将返回BooleanQuery
,其evaluate()
方法返回一个布尔值。修改您提供的代码将为您提供
BooleanQuery booleanQuery = con.prepareBoleanQuery(QueryLanguage.SPARQL, queryString);
boolean result = booleanQuery.evaluate();