Reputation: 577
I am executing a query in neo4j using java. I don't know how to check if the execution result is empty. Here is my code.
String firstquery=" start n=node(*) match(b)-[relatedto]->(n) where b.value=\""+applicationName+"\" return n";
ExecutionResult execResult = execEngine.execute(firstquery);
System.out.println("executing query");
String results = execResult.dumpToString();
System.out.println(results);
Iterator<Node> n_column1 = execResult.columnAs( "n" );
System.out.println("n column 1 :"+n_column1);
if (n_column1 ==null)
{
System.out.println("Has no rows");
}
else
{
System.out.println("results are there");
}
My results.dumpToString()
looks like this. I am confused over the condition in the if
that will check if it has 0 results or not.
+---+
| n |
+---+
+---+
0 row
Upvotes: 1
Views: 1035
Reputation: 4080
An execution result is essentially an iterator of a map, its type definition is something like:
Iterable<Map<String,Object>>
So you can easily just do:
result.iterator().hasNext();
I think that its strictly a ResourceIterator, so if you get an iterator you are supposed to close it if you don't exhaust it. Check the neo4j documentation for ResourceIterator.
Upvotes: 4