tags:

views:

114

answers:

2

CONSTRUCT is an alternative SPARQL result clause to SELECT. Instead of returning a table of result values, CONSTRUCT returns an RDF graph.

So running this query

PREFIX : http://dbpedia.org/resource/
PREFIX onto: http://dbpedia.org/ontology/ 
CONSTRUCT { 
:France onto:anthem ?x
}
WHERE
{
:France onto:anthem ?x .
}

dont foget the < and > arround prefix

inside this java code:

Query query = QueryFactory.create("the query goes here");
QueryExecution qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query);
ResultSet results = qexec.execSelect();  
ResultSetFormatter.out(System.out, results, query);

it returns HttpException: 406 Unacceptable. But if instead of the contruct block, i choose select ?x, its just fine. Does jena support construct, how?

trying on http://dbpedia.org/snorql both work well. T

+1  A: 

Jena supports CONSTRUCT, but to get the result you need to call a different method, because execSelect and ResultSet are only for SELECT queries. Use this instead:

Model results = qexec.execConstruct();
results.write(System.out, "TURTLE");

Model is Jena's interface for accessing RDF graphs, see the javadocs for details.

cygri
worked perfectly, the write method does all the work for me, thx
blueomega
A: 

ResultSetFormatter.out(System.out, results, query) cannot find symbol and identifier expected error occurs at this point

Avaya