Bonsoir tout le monde,
je suis encore débutante en Java, j'ai ce code et je cherche comment faire pour stocker le résultat de la requête sparql dans un vecteur, merciiiiiiiiii d'avance
URL url;
Vector<Query>v=new Vector<Query>();
try{
String queryString = "SELECT ?nom ?label ?comment WHERE { " +
"<http://dbpedia.org/resource/Monograph> <http://www.w3.org/2000/01/rdf-schema#nom> ?nom." +
"<http://dbpedia.org/resource/Monograph> <http://www.w3.org/2000/01/rdf-schema#label> ?label." +
"<http://dbpedia.org/resource/Monograph> <http://www.w3.org/2000/01/rdf-schema#comment> ?comment." +
" FILTER langMatches(lang(?nom), 'en') " +
" FILTER langMatches(lang(?label), 'en') " +
" FILTER langMatches(lang(?comment), 'en')}";
Query query = QueryFactory.create(queryString);
// initializing queryExecution factory with remote service.
// **this actually was the main problem I couldn't figure out.**
QueryExecution qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query);
try {
ResultSet results = qexec.execSelect();
for (; results.hasNext() {
QuerySolution sol = results.next();
System.out.println(sol.get("?nom") + "\n"+ sol.get("?label") + "\n" + sol.get("?comment"));
}
}catch(Exception e){
e.printStackTrace();
}
finally {
qexec.close();
}
}catch(Exception e){
e.printStackTrace();
}
Partager