Atouray
asked on
convert sparql query results into string array
I am trying to convert my sparql query results into string but i get some weird errors
WARN [main] (Log.java:63) - StAX error: End of document while processing solution
Exception in thread "main" com.hp.hpl.jena.sparql.res ultset.Res ultSetExce ption: End of document while processing solution
at com.hp.hpl.jena.sparql.res ultset.XML InputStAX$ ResultSetS tAX.staxEr ror(XMLInp utStAX.jav a:504)
at com.hp.hpl.jena.sparql.res ultset.XML InputStAX$ ResultSetS tAX.getOne Solution(X MLInputStA X.java:412 )
at com.hp.hpl.jena.sparql.res ultset.XML InputStAX$ ResultSetS tAX.hasNex t(XMLInput StAX.java: 216)
at com.hp.hpl.jena.sparql.res ultset.Res ultSetMem. <init>(Res ultSetMem. java:82)
at com.hp.hpl.jena.sparql.res ultset.Tex tOutput.wr ite(TextOu tput.java: 133)
at com.hp.hpl.jena.sparql.res ultset.Tex tOutput.wr ite(TextOu tput.java: 116)
at com.hp.hpl.jena.sparql.res ultset.Tex tOutput.wr ite(TextOu tput.java: 104)
at com.hp.hpl.jena.sparql.res ultset.Tex tOutput.fo rmat(TextO utput.java :51)
at com.hp.hpl.jena.query.Resu ltSetForma tter.out(R esultSetFo rmatter.ja va:109)
at query4.longplace(query4.ja va:281)
at query4.main(query4.java:81 )
My code is
WARN [main] (Log.java:63) - StAX error: End of document while processing solution
Exception in thread "main" com.hp.hpl.jena.sparql.res
at com.hp.hpl.jena.sparql.res
at com.hp.hpl.jena.sparql.res
at com.hp.hpl.jena.sparql.res
at com.hp.hpl.jena.sparql.res
at com.hp.hpl.jena.sparql.res
at com.hp.hpl.jena.sparql.res
at com.hp.hpl.jena.sparql.res
at com.hp.hpl.jena.sparql.res
at com.hp.hpl.jena.query.Resu
at query4.longplace(query4.ja
at query4.main(query4.java:81
My code is
final String queryString2 =
"PREFIX foaf: <http://xmlns.com/foaf/0.1/>"+
"PREFIX dbp: <http://dbpedia.org/property/>"+
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"+
"PREFIX dbont: <http://dbpedia.org/ontology/>"+
"PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>"+
"PREFIX dbo: <http://dbpedia.org/ontology/>"+
"SELECT DISTINCT ?long "+
"WHERE {"+
"?actor dbont:birthPlace ?place ."+
//"?place geo:lat ?lat ."+
"?place geo:long ?long ."+
"FILTER(?actor=<"+fakeactor.toString()+">)"+
"}";
// now creating query object
com.hp.hpl.jena.query.Query query = QueryFactory.create(queryString2);
// initializing queryExecution factory with remote service.
QueryExecution qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query);
final com.hp.hpl.jena.query.ResultSet lng = qexec.execSelect();
//ResultSet lngs = (java.sql.ResultSet) qexec.execSelect();
String w= ResultSetFormatter.asText(lng, query);
//qexec.execSelect().getResultVars();
//System.out.println(w);
ResultSetFormatter.out(System.out, lng, query);
check that the query is returning a valid result set
ASKER
The query is returning a valid result set. Anymore ideas?
> String w= ResultSetFormatter.asText( lng, query);
this line appears to be actually working
whats the value of w?
this line appears to be actually working
whats the value of w?
ASKER
This the line that gives me the error!
no the errors coming from:
ResultSetFormatter.out(Sys tem.out, lng, query);
ResultSetFormatter.out(Sys
ASKER
If I run this method without the String w= ResultSetFormatter.asText( lng, query); I have proper results!
What do you suggest me to use instead of ResultSetFormatter.out(Sys tem.out, lng, query); ?
What do you suggest me to use instead of ResultSetFormatter.out(Sys
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
But the first one gives me errors...not working at all!
what errors?