i test this sparql query in jena-fuseki-1.1.1 it is working but when i use in jena java project it is not give me output.inside while loop not executing.
private static void sparqlTst() {
FileManager.get().addLocatorClassLoader(Jena_Enigma.class.getClassLoader());
Model model = FileManager.get().loadModel("http://www.heshjayasinghe.webatu.com/Enigma.RDF");
model.write(System.out, "RDF/JSON");
String queryString = "PREFIX sep: <http://www.heshjayasinghe.webatu.com/Enigma.RDF#>"
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>"
+ "PREFIX strg: <http://www.w3.org/2001/XMLSchema#string#>"
+ "SELECT ?first "
+ "WHERE {"
+ "?User sep:email \"heshjse@gmail.com\"."
+ "?User sep:password \"123\"."
+ "?User sep:fname ?first. "
+ "}";
Query query = QueryFactory.create(queryString);
// System.out.println(query);
QueryExecution qexec = QueryExecutionFactory.create(query, model);
try {
ResultSet results = qexec.execSelect();
System.out.println(results);
while (results.hasNext()) {
System.out.println("ok");
QuerySolution soln = results.nextSolution();
System.out.println(soln);
Literal name = soln.getLiteral("x");
System.out.println(name);
System.err.printf("X is '%s'\n", soln.getLiteral("first"));
}
} finally {
qexec.close();
}
}
corrected answer
private static void sparqlTst() {
FileManager.get().addLocatorClassLoader(Jena_Enigma.class.getClassLoader());
Model model = FileManager.get().loadModel("http://www.heshjayasinghe.webatu.com/Enigma.RDF");
model.write(System.out, "RDF/JSON");
String queryString = "PREFIX sep: <http://www.heshjayasinghe.webatu.com/Enigma.RDF#>"
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>"
+ "PREFIX strg: <http://www.w3.org/2001/XMLSchema#string#>"
+ "SELECT ?x "
+ "WHERE {"
+ "?User sep:email \"heshjse@gmail.com\"."
+ "?User sep:password \"123\"."
+ "?User sep:fname ?x. "
+ "}";
Query query = QueryFactory.create(queryString);
// System.out.println(query);
QueryExecution qexec = QueryExecutionFactory.create(query, model);
try {
ResultSet results = qexec.execSelect();
System.out.println(results);
while (results.hasNext()) {
QuerySolution soln = results.nextSolution();
Literal name = soln.getLiteral("x");
System.out.println(name);
}
} finally {
qexec.close();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.