Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

convert sparql query results into string array

Posted on 2011-02-21
9
Medium Priority
?
1,502 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Atouray
ID: 34948194
This the line that gives me the error!
0
 
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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
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:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

610 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