Reputation: 43
After excecuting a query in sparql jena, I tried to get the query result as a list, so I used this:
res = ResultSetFormatter.toList(results);
but when I write this method before that method the variable res
returns null.
ResultSetFormatter.out(System.out, results);
res = ResultSetFormatter.toList(results);
I don't know what is the problem.
Upvotes: 2
Views: 595
Reputation: 552
The main ResultSet
implementation is com.hp.hpl.jena.sparql.engine.ResultSetStream
which can only be used once, whereas you are trying to use it twice. The API documentation for ResultSetStream
says:
The main ResultSet implementation for returning results from queries. This version is "use once" - you can not reset the result set because the results of the query are not remembered so as not to consume potentially large amounts of memory.
Upvotes: 3
Reputation: 22053
At a guess, I'd say ResultSetFormatter.out(ResultSet)
consumes the ResultSet
. So after this method has completed, ResultSet
is empty.
It's somewhat comparable to how an Iterator
works: once you've iterated over all the elements, the iterator is empty.
Upvotes: 2