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] ( - 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(
      at com.hp.hpl.jena.sparql.resultset.XMLInputStAX$ResultSetStAX.getOneSolution(
      at com.hp.hpl.jena.sparql.resultset.XMLInputStAX$ResultSetStAX.hasNext(
      at com.hp.hpl.jena.sparql.resultset.ResultSetMem.<init>(
      at com.hp.hpl.jena.sparql.resultset.TextOutput.write(
      at com.hp.hpl.jena.sparql.resultset.TextOutput.write(
      at com.hp.hpl.jena.sparql.resultset.TextOutput.write(
      at com.hp.hpl.jena.sparql.resultset.TextOutput.format(
      at com.hp.hpl.jena.query.ResultSetFormatter.out(
      at query4.longplace(
      at query4.main(
My code is
	final String queryString2 = 
			"PREFIX foaf: <>"+
			"PREFIX dbp: <>"+
			"PREFIX rdf: <>"+
			"PREFIX dbont: <>"+
			"PREFIX geo: <>"+
			"PREFIX dbo: <>"+

			"SELECT DISTINCT  ?long "+
			"WHERE {"+
			      	"?actor dbont:birthPlace ?place ."+
			      	//"?place geo:lat ?lat ."+
			      	"?place geo:long ?long ."+

		// now creating query object
		com.hp.hpl.jena.query.Query query = QueryFactory.create(queryString2);
		// initializing queryExecution factory with remote service.
		QueryExecution qexec = QueryExecutionFactory.sparqlService("", query);
		final com.hp.hpl.jena.query.ResultSet lng = qexec.execSelect();
        //ResultSet lngs = (java.sql.ResultSet) qexec.execSelect();
        String w= ResultSetFormatter.asText(lng, query);  
		ResultSetFormatter.out(System.out, lng, query);

Open in new window

Who is Participating?
objectsConnect With a Mentor Commented:
you can only do one or the other. once you have read the result set you cannot read it again
the first one would probably be better, as you can then do what you want with the string
check that the query is returning a valid result set
AtourayAuthor Commented:
The query is returning a valid result set. Anymore ideas?
Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

>         String w= ResultSetFormatter.asText(lng, query);  

this line appears to be actually working
whats the value of w?
AtourayAuthor Commented:
This the line that gives me the error!
no the errors coming from:

            ResultSetFormatter.out(System.out, lng, query);
AtourayAuthor Commented:
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);  ?
AtourayAuthor Commented:
But the first one gives me errors...not working at all!
what errors?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.