# Neo4j embedded graph java visualization

**URL:** <https://community.neo4j.com/t/neo4j-embedded-graph-java-visualization/13015>\
**Category:** Java\
**Created:** [December 19, 2019, 10:30am UTC](https://community.neo4j.com/t/neo4j-embedded-graph-java-visualization/13015 "2019-12-19T10:30:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nico.pelissero](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/nico.pelissero/32/8131_2.png) [@nico.pelissero](https://community.neo4j.com/u/nico.pelissero)\
**Post date:** [December 19, 2019, 10:30am UTC](https://community.neo4j.com/t/neo4j-embedded-graph-java-visualization/13015/1 "2019-12-19T10:30:30Z")

</div>

Hi,  
I'm beginning in Neo4j java embedded graph.  
I have made a first test but I cant visualize my graph in neo4j-community.

Here is my code for create the graph :

```auto
package connection;

import java.io.File;

import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;

public class embededdedGraph {

	public static void main(String... args) throws Exception {
		GraphDatabaseFactory graphDbFactory = new GraphDatabaseFactory();
		File graphDir = new File("/home/nicolas/neo4j-community-3.5.14/data/databases/cars.db");
		GraphDatabaseService graphDb = graphDbFactory.newEmbeddedDatabase(graphDir);
		Transaction tx = graphDb.beginTx();
		
		createNode(graphDb);
	
		tx.close();

	}
	
	public static void createNode(GraphDatabaseService graphDb) {
		Node car = graphDb.createNode();
		car.addLabel(Label.label("Car"));

		car.setProperty("make", "tesla");
		car.setProperty("model", "model3");

		Node owner = graphDb.createNode(Label.label("Person"));
		owner.setProperty("firstName", "Oliver");
		owner.setProperty("lastName", "John");
		owner.createRelationshipTo(car, RelationshipType.withName("owner"));
	}

}

```

Next I change the value of "#dbms.active\_database" to "dbms.active\_database=cars.db.

When I restart neo4j-community the db name is "cars.db" but it's indicated there no labels and relationships in the database.

Thanks a lot,

Nicolas.

---

<div class="post-metadata">

**Author:** ![mark.andrews](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/mark.andrews/32/2926_2.png) [@mark.andrews](https://community.neo4j.com/u/mark.andrews)\
**Post date:** [December 19, 2019, 2:57pm UTC](https://community.neo4j.com/t/neo4j-embedded-graph-java-visualization/13015/2 "2019-12-19T14:57:28Z")

</div>

You have to call `tx.success();` before calling `tx.close();` in order to have the changes committed. Best practice is to wrap the transaction in a `try` block like this:

```auto
  Transaction tx=graphDb.beginTx();
  try {
    createNode(graphDB);
    tx.success();
  }
  finally {
    tx.finish();
  }

```

HTH

---

<div class="post-metadata">

**Author:** ![nico.pelissero](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/nico.pelissero/32/8131_2.png) [@nico.pelissero](https://community.neo4j.com/u/nico.pelissero)\
**Post date:** [December 20, 2019, 8:50pm UTC](https://community.neo4j.com/t/neo4j-embedded-graph-java-visualization/13015/3 "2019-12-20T20:50:58Z")

</div>

Thanks for your answer !

Nicolas
