Solved

convert sparql query results into string array

Posted on 2011-02-21
9
1,466 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 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

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
junit example issue 2 54
StoredProcedure to JSON query faulty syntax 2 45
How to add an Index to a date/time field? 15 40
T-SQL: Number of Records is Greater Than One 7 50
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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…
This video teaches viewers about errors in exception handling.
Suggested Courses

739 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