Solved

convert sparql query results into string array

Posted on 2011-02-21
9
1,409 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:Atouray
  • 5
  • 4
9 Comments
 
LVL 92

Expert Comment

by:objects
ID: 34948094
check that the query is returning a valid result set
0
 

Author Comment

by:Atouray
ID: 34948133
The query is returning a valid result set. Anymore ideas?
0
 
LVL 92

Expert Comment

by:objects
ID: 34948175
>         String w= ResultSetFormatter.asText(lng, query);  

this line appears to be actually working
whats the value of w?
0
 

Author Comment

by:Atouray
ID: 34948194
This the line that gives me the error!
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 92

Expert Comment

by:objects
ID: 34948204
no the errors coming from:

            ResultSetFormatter.out(System.out, lng, query);
0
 

Author Comment

by:Atouray
ID: 34948246
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);  ?
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 34948321
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
0
 

Author Comment

by:Atouray
ID: 34948352
But the first one gives me errors...not working at all!
0
 
LVL 92

Expert Comment

by:objects
ID: 34948375
what errors?
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now