I am new to Neo4j and I would like to query a Neo4j database containing only nodes in order to create links between them according to 2 lists I already have.
For example, I want to connect nodes with names in a List A with nodes with names from List B.
This is the code I wrote :
public class Main {
public static void main(String[] args) {
GraphDatabaseFactory graphDbFactory = new GraphDatabaseFactory();
GraphDatabaseService graphDb = graphDbFactory.newEmbeddedDatabase("C:\\Zakaria\\NeoTests\\Tetralecture");
ExecutionEngine execEngine = new ExecutionEngine(graphDb);
/* Here is a loop to read from listA and listB so no need to worry about them */
try (Transaction ignored = graphDb.beginTx()) {
String query = "MATCH (auteur1:AUTEUR{Name:'" + listA.get(i) + "'}), (auteur2:AUTEUR{Name:'" + listB.get(j) + "'}) return auteur1, auteur2";
ExecutionResult execResult = execEngine.execute(query);
Iterator<Node> aut_column = execResult.columnAs("auteur1");
for(Node node : IteratorUtil.asIterable(aut_column)) {
String nodeResult = node + " : " + node.getProperty("Name");
System.out.println(nodeResult);
}
}
}
}
This example only displays one list of authors from one colunm auteur1, I would like to be able to display both of them.
If I can do that, I think maniputating the nodes from both lists and creating links between them would be easier.
Thanks for your help!