为什么我得到这个 sparql 查询的单个结果?

Why am i getting a single result for this sparql query?

我在 sparql 端点执行了查询并得到了多个结果。但是在 Netbeans 中执行它时,我只得到一个结果。 public class FetchCountryData {

public void fetchData() {
    ParameterizedSparqlString qs = new ParameterizedSparqlString("PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
            + "PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>\n"
            + "PREFIX dbo: <http://dbpedia.org/ontology/>\n"
            + "\n"
            + "SELECT distinct ?country ?capital ?caplat ?caplong\n"
            + "WHERE {\n"
            + "  ?country rdf:type dbo:Country .\n"
            + "  ?country  dbo:capital ?capital .\n"
            + "  OPTIONAL {\n"
            + "    ?capital geo:lat ?caplat ;\n"
            + "      geo:long ?caplong .\n"
            + "  }\n"
            + "}\n"
            + "ORDER BY ?country");

    QueryExecution exec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", qs.asQuery());
    exec.setTimeout(10000000);
    ResultSet results = exec.execSelect();
    if (results.hasNext()) {
        System.out.println(results.next());
    }
}

}

输出

( ?capital = http://dbpedia.org/resource/Nicosia ) ( ?caplong = "33.3667"^^xsd:float ) ( ?caplat = "35.1667"^^xsd:float ) ( ?country <=http://dbpedia.org/resource/1974_Cypriot_coup_d'état> )

您没有迭代结果。将 "if" 更改为:

while (results.hasNext()){
System.out.println(results.next());
}