Executing SPARQL Queries:
import org.apache.jena.query.Query;import org.apache.jena.query.QueryExecution;import org.apache.jena.query.QueryExecutionFactory;import org.apache.jena.query.QueryFactory;import org.apache.jena.query.ResultSet;import org.apache.jena.query.ResultSetFormatter; public class QueryExample { public static void main(String[] args) { String queryString = "SELECT ?s ?p ?o WHERE { ?s ?p ?o }"; Query query = QueryFactory.create(queryString); try (QueryExecution qexec = QueryExecutionFactory.create(query, model)) { ResultSet results = qexec.execSelect(); ResultSetFormatter.out(System.out, results, query); } }}