Link to home
Start Free TrialLog in
Avatar of Atouray
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.resultset.ResultSetException: End of document while processing solution
      at com.hp.hpl.jena.sparql.resultset.XMLInputStAX$ResultSetStAX.staxError(XMLInputStAX.java:504)
      at com.hp.hpl.jena.sparql.resultset.XMLInputStAX$ResultSetStAX.getOneSolution(XMLInputStAX.java:412)
      at com.hp.hpl.jena.sparql.resultset.XMLInputStAX$ResultSetStAX.hasNext(XMLInputStAX.java:216)
      at com.hp.hpl.jena.sparql.resultset.ResultSetMem.<init>(ResultSetMem.java:82)
      at com.hp.hpl.jena.sparql.resultset.TextOutput.write(TextOutput.java:133)
      at com.hp.hpl.jena.sparql.resultset.TextOutput.write(TextOutput.java:116)
      at com.hp.hpl.jena.sparql.resultset.TextOutput.write(TextOutput.java:104)
      at com.hp.hpl.jena.sparql.resultset.TextOutput.format(TextOutput.java:51)
      at com.hp.hpl.jena.query.ResultSetFormatter.out(ResultSetFormatter.java:109)
      at query4.longplace(query4.java:281)
      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);
	

Open in new window

Avatar of Mick Barry
Mick Barry
Flag of Australia image

check that the query is returning a valid result set
Avatar of Atouray
Atouray

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?
Avatar of Atouray

ASKER

This the line that gives me the error!
no the errors coming from:

            ResultSetFormatter.out(System.out, lng, query);
Avatar of Atouray

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(System.out, lng, query);  ?
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Atouray

ASKER

But the first one gives me errors...not working at all!
what errors?