Reputation: 558
I have companies that have logged in and created a relations of debt to other companies . I want to make a query to ask who has created relations (get the first nodes in a relation)
I do it like this
ExecutionEngine engine = new ExecutionEngine(graphDB);
ExecutionResult result = engine.execute( "start n=node(*) match n-[r]->() return distinct n.name");
When I do
out.println("Companies that have entered data "+result.toString());
I get what I wanted, but now I need to display it in the right way for my servlet. I currently do it like this
Iterator<Node> list_companies = result.columnAs("n.name");
while(list_companies.hasNext()){
Node compan = list_companies.next();
out.println(compan.getId()+" "+compan.getProperty("name"));
}
And I get no results. My nodes have properties name, tax number and email. I do not think that the right way to do it is to parse
result.toString()
by removing " | +---||"...
Upvotes: 0
Views: 684
Reputation: 19373
If you are returning n.name then you'll have a property returned and not a Node:
Iterator<Node> list_companies = result.columnAs("n.name");
should most likely be:
Iterator<String> list_companies = result.columnAs("n.name");
while(list_companies.hasNext()){
String compan = list_companies.next();
out.println(compan);
}
If you want the id and the name properties then you could return distinct n and then it would be a Node iterator as in your example.
Upvotes: 3