Vini
Vini

Reputation: 323

How to perform ASK queries?

If I want to do a SPARQL SELECT query in in Sesame repository through Netbeans, I use the following code (and I get three values in the binding set). How can I do an ASK query which return just one boolean?

TupleQuery tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
TupleQueryResult result = tupleQuery.evaluate();
List<String> bindingNames = result.getBindingNames();

try {
    while (result.hasNext()) {    
        BindingSet bindingSet = result.next();
        Value firstValue1 = bindingSet.getValue(bindingNames.get(0));
        Value firstValue2 = bindingSet.getValue(bindingNames.get(1));
        Value firstValue3 = bindingSet.getValue(bindingNames.get(2));
    }
}

Upvotes: 0

Views: 234

Answers (1)

Joshua Taylor
Joshua Taylor

Reputation: 85883

Assuming that your con is a RepositoryConnection, you'd use some version of prepareBooleanQuery(…). That will return a BooleanQuery whose evaluate() method returns a boolean. Modying the code you presented would leave you with

BooleanQuery booleanQuery = con.prepareBoleanQuery(QueryLanguage.SPARQL, queryString);
boolean result = booleanQuery.evaluate();

Upvotes: 3

Related Questions