// write TSV result to STDOUT (to write to file, use a FileoutputStream instead)
SPARQLResultsTSVWriter writer = new SPARQLResultsTSVWriter(System.out);
try (RepositoryConnection conn = rep.getConnection()) {
String query = "SELECT ... ";
// execute the query and stream the result to the supplied writer
conn.prepareTupleQuery(query).evaluate(writer);
}
如果您需要更漂亮的东西,您可以编写自己的自定义查询结果处理程序,并使用它来代替
SPARQLResultsTSVWriter
. 为此,创建一个新的类来扩展
AbstractQueryResultWriter
,并重写其中任何需要自定义的方法(特别是,
handleNamespace
handleSolution
,
startQueryResult
和
endQueryResult