I am trying to query an open RDF repository which is loaded with a turtle file. When I am selecting all with a query - "SELECT ?s WHERE { ?s ?p ?o } "; then everything is working fine but when I am using a little complex query then its not working. I am attaching the code for the query portion -
private static void queryingRDF(Repository repo) {
try{
RepositoryConnection con = repo.getConnection();
try{
String queryString = "SELECT ?s WHERE { ?s uml:lineOfBusiness cp:lobEQUITIES .}" ;
TupleQuery tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
TupleQueryResult result = tupleQuery.evaluate();
try {
while(result.hasNext()){
BindingSet bindingSet = result.next();
Value valueOfX = bindingSet.getValue("s");
//Value valueOfY = bindingSet.getValue("p");
//Value valueOfZ = bindingSet.getValue("o");
//System.out.println(valueOfX + " " + valueOfY + " " + valueOfZ);
System.out.println(valueOfX) ;
}
}
finally {
result.close();
}
}
finally{
con.close();
}
}
catch(OpenRDFException e){
System.out.println("Query error");
}
}
This is continuously getting into the exception section and throwing the error - "Query Error". Whats is going wrong?
It looks like you don't define the uml
or cp
prefixes. I'm looking for a statement like this in your querystring:
PREFIX uml: <http://example.com/uml>
or a call to RepositoryConnection::setNamespace like this:
con.setNamespace("uml", "http://example.com/uml");