[英]jena.query.ResultSet and jena.query.QuerySolution: hasNext() returns alway false after SPARQL request
[英]jena.query.ResultSet and jena.query.QuerySolution: empty iterator after SPARQL request
A有接收SPARQL響應的問題。 問題是方法((ResultSet) response).hasNext()
返回false
盡管響應不應為空。
要求是:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ontology: <http://www.semanticweb.org/kseniia/ontologies/2013/1/untitled-ontology-12#> SELECT ?x
WHERE {?x rdfs:subClassOf ontology:Visual}
這在Protege中正常工作並返回3個對象:
Location
Relation
Descriptive
查詢以jena的方式執行:
Query query = QueryFactory.create(queryString);
QueryExecution qexec = QueryExecutionFactory.create(query, model);
Object response = qexec.execSelect();
qexec.close();
for ( ; ((ResultSet) response).hasNext(); ) { // always false
QuerySolution soln = ((ResultSet) response).nextSolution();
// etc
}
也許我錯過了什么?
您正在使用qexec.close
關閉執行,然后迭代結果。 除了結果由qexec.close
關閉且不再可用。
將qexec.close
移動到循環之后。
改進:
Object response
==> ResultSet response
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.