public
static
void testQuery() {
try {
RepositoryConnection con = repo.getConnection();
try {
String queryString =
"PREFIX rk:<http://rk.com/test/> "
+
"SELECT ?s ?o "
+
"WHERE { "
+
"?s rk:type rk:CreativeWork ."
+
"?s ?p ?o ."
+
"} "
;
TupleQuery tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
long startTime = System.currentTimeMillis();
TupleQueryResult result = tupleQuery.evaluate();
long secondTime = System.currentTimeMillis();
List<String> bindingNames = result.getBindingNames(); //get the
name
of
binded variables
while (result.hasNext()) {
BindingSet bindingSet = result.
next
();
Value firstValue = bindingSet.getValue(
"s"
); //bindingSet.getValue(bindingNames.get(0));
Value secondValue = bindingSet.getValue(
"o"
); //bindingSet.getValue(bindingNames.get(1));
System.
out
.println(firstValue);
System.
out
.println(secondValue);
// do something interesting
with
the
values
here...
}
long endTime = System.currentTimeMillis();
System.
out
.println(
"evaluation time = "
+(secondTime-startTime));
System.
out
.println(
"fetch time = "
+(endTime-secondTime));
}
finally {
con.
close
();
}
}
catch (OpenRDFException e) {
// handle exception
e.printStackTrace();
}
}