{
public static void main(String... argv)
{
// Direct way: Make a TDB-back Jena model in the named directory.
String directory = "MyDatabases/DB1" ;
Dataset dataset = TDBFactory.createDataset(directory) ;
// Potentially expensive query.
String sparqlQueryString = "SELECT (count(*) AS ?count) { ?s ?p ?o }" ;
// See http://www.openjena.org/ARQ/app_api.html
Query query = QueryFactory.create(sparqlQueryString) ;
QueryExecution qexec = QueryExecutionFactory.create(query, dataset) ;
try {
ResultSet results = qexec.execSelect() ;
for ( ; results.hasNext() ; )
{
QuerySolution soln = results.nextSolution() ;
int count = soln.getLiteral("count").getInt() ;
System.out.println("count = "+count) ;
}
} finally { qexec.close() ; }
// Close the dataset.
dataset.close();
}