RH1212354
RH1212354

Reputation: 17

creating a Neo4j node using java code

I am trying to create a new node in the neo4j database graph.db using java, I am trying to execute this code:

GraphDatabaseFactory dbFactory = new GraphDatabaseFactory();
  GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase("./users/rih/neo4j-2.2.5/data/graph.db");



try(Transaction tx=db.beginTx()){
    Node nod=db.createNode(NodeType.course);
    nod.setProperty("name", "comp");
    Node nodrim=db.createNode(NodeType.course);
    nod.setProperty("name", "info");

  }

But nothing is showing on the graph database,the nodes are not added. pleaaasee help.

Upvotes: 0

Views: 1028

Answers (2)

Govind Mantri
Govind Mantri

Reputation: 803

As @Luanne suggest and a addition to it is to close the transaction if no further use is there. tx.success(); tx.close(); transcation should be closed at the end.

Upvotes: 0

Luanne
Luanne

Reputation: 19373

You need to make sure that you commit the transaction-

tx.success()

Upvotes: 3

Related Questions