Discussion:
resultset as string
neha gupta
2016-11-03 12:37:24 UTC
Permalink
I have a query which has output of one single string line "My name is ---,
living in city -----, located in country ----.

After query string , I have executed the query

Query query = QueryFactory.create(queryString);
QueryExecution qexec = QueryExecutionFactory.create(query, model) ;
ResultSet rs = qexec.execSelect() ;
I want this string to be displayed as string:
JOptionPane.showMessageDialog(null, string);

But I dont think I need while(rs.hasNext()) and convert it to string
because resultset only contain one string output at one time.
How can I display the resultset as string?
Martynas Jusevičius
2016-11-03 12:55:06 UTC
Permalink
See ResultSetFormatter:
https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/query/ResultSetFormatter.html
Post by neha gupta
I have a query which has output of one single string line "My name is ---,
living in city -----, located in country ----.
After query string , I have executed the query
Query query = QueryFactory.create(queryString);
QueryExecution qexec = QueryExecutionFactory.create(query, model) ;
ResultSet rs = qexec.execSelect() ;
JOptionPane.showMessageDialog(null, string);
But I dont think I need while(rs.hasNext()) and convert it to string
because resultset only contain one string output at one time.
How can I display the resultset as string?
Lorenz B.
2016-11-03 13:00:20 UTC
Permalink
If you know that there is exactly 1 result why does it not work to call
just once rs.next() ? E.g.

rs.next().getLiteral(THE_VAR_NAME).getLexicalForm();

Lorenz
Post by neha gupta
I have a query which has output of one single string line "My name is ---,
living in city -----, located in country ----.
After query string , I have executed the query
Query query = QueryFactory.create(queryString);
QueryExecution qexec = QueryExecutionFactory.create(query, model) ;
ResultSet rs = qexec.execSelect() ;
JOptionPane.showMessageDialog(null, string);
But I dont think I need while(rs.hasNext()) and convert it to string
because resultset only contain one string output at one time.
How can I display the resultset as string?
--
Lorenz BÃŒhmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center
neha gupta
2016-11-03 13:35:46 UTC
Permalink
Thanks Lorenz, I did not know about this method.


On Thu, Nov 3, 2016 at 3:00 PM, Lorenz B. <
Post by Lorenz B.
If you know that there is exactly 1 result why does it not work to call
just once rs.next() ? E.g.
rs.next().getLiteral(THE_VAR_NAME).getLexicalForm();
Lorenz
Post by neha gupta
I have a query which has output of one single string line "My name is
---,
Post by neha gupta
living in city -----, located in country ----.
After query string , I have executed the query
Query query = QueryFactory.create(queryString);
QueryExecution qexec = QueryExecutionFactory.create(query, model) ;
ResultSet rs = qexec.execSelect() ;
JOptionPane.showMessageDialog(null, string);
But I dont think I need while(rs.hasNext()) and convert it to string
because resultset only contain one string output at one time.
How can I display the resultset as string?
--
Lorenz BÃŒhmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center
neha gupta
2016-11-03 13:53:19 UTC
Permalink
It gives me error:

NoSuchElementException: QueryIteratorCloseable
t
com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorBase.nextBinding(QueryIteratorBase.java:93)
Post by neha gupta
Thanks Lorenz, I did not know about this method.
Post by Lorenz B.
If you know that there is exactly 1 result why does it not work to call
just once rs.next() ? E.g.
rs.next().getLiteral(THE_VAR_NAME).getLexicalForm();
Lorenz
Post by neha gupta
I have a query which has output of one single string line "My name is
---,
Post by neha gupta
living in city -----, located in country ----.
After query string , I have executed the query
Query query = QueryFactory.create(queryString);
QueryExecution qexec = QueryExecutionFactory.create(query, model) ;
ResultSet rs = qexec.execSelect() ;
JOptionPane.showMessageDialog(null, string);
But I dont think I need while(rs.hasNext()) and convert it to string
because resultset only contain one string output at one time.
How can I display the resultset as string?
--
Lorenz BÃŒhmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center
Andy Seaborne
2016-11-03 20:54:53 UTC
Permalink
Either
* your query is not returning one line
* you called .next once already and then called it again

Once again you do not provide a complete, minimal example. No one can
tell which of these is happening.

Read this
http://stackoverflow.com/help/mcve

Andy
Post by neha gupta
NoSuchElementException: QueryIteratorCloseable
t
com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorBase.nextBinding(QueryIteratorBase.java:93)
^^^^^^^^^^^^^^^^^^^

Your version of Jena is out of date.
Post by neha gupta
Post by neha gupta
Thanks Lorenz, I did not know about this method.
Post by Lorenz B.
If you know that there is exactly 1 result why does it not work to call
just once rs.next() ? E.g.
rs.next().getLiteral(THE_VAR_NAME).getLexicalForm();
Lorenz
Post by neha gupta
I have a query which has output of one single string line "My name is
---,
Post by neha gupta
living in city -----, located in country ----.
After query string , I have executed the query
Query query = QueryFactory.create(queryString);
QueryExecution qexec = QueryExecutionFactory.create(query, model) ;
ResultSet rs = qexec.execSelect() ;
JOptionPane.showMessageDialog(null, string);
But I dont think I need while(rs.hasNext()) and convert it to string
because resultset only contain one string output at one time.
How can I display the resultset as string?
--
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center
Loading...