在 sparql jena 中执行查询后,我尝试以列表形式获取查询结果,因此我使用了以下内容:
res = ResultSetFormatter.toList(results);
但是当我在该方法之前编写此方法时,变量 res
返回 null。
ResultSetFormatter.out(System.out, results);
res = ResultSetFormatter.toList(results);
我不知道问题出在哪里。
最佳答案
主要的ResultSet
实现是com.hp.hpl.jena.sparql.engine.ResultSetStream
,它只能使用一次,而您试图使用它两次。 API documentation对于 ResultSetStream
说:
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.
关于sparql - 语义网 - Jena sparql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10625841/