Solved

convert sparql query results into string array

Posted on 2011-02-21
9
1,438 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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql query to calculate avaerage 21 52
Crystal Reports Licensing Questions 4 34
Procedure syntax 5 38
Tagging and Merging on Branch 1 29
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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 learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
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:

789 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