Creating Node in Embedded Neo4J Application with Cypher

Viewed 190

I'm integrating my system with neo4j and it would be interesting to me to create nodes using the Cypher query language, therefore, as a test, I'm trying to do something like this:

String path = "test.graphdb";

AbstractDatabase db = new Neo4jDatabase(path, true, false);

db.makeQuery("CREATE (n:Dog {name:'Sofia'})");
db.makeQuery("CREATE (n:Dog {name:'Laika'})");     db.makeQuery("CREATE (n:Dog {name:'Gaia'})");

Result result = db.makeQuery("MATCH (n:Dog) RETURN n");

boolean hasNext = result.hasNext();

System.out.println(hasNext);

Where inside the Neo4jDatabase class I have this makeQuery method which goes like this:

public Result makeQuery(String string)
{
    try(Transaction ignored = this.db.beginTx();
        Result result = this.db.execute(string) )
    {
        return result;
    }

}

Unfortunately, it returns false, as if the nodes had not been created! What is wrong?

1 Answers
Related