Java embedded graph in Neo4j community 4.1.1

Hi all ! I trying to visualize a java embedded graph in Neo4j community.

There is my code to generate the new.db I want to visualize:

 * Licensed to Neo4j under one or more contributor
 * license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright
 * ownership. Neo4j licenses this file to you under
 * the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.


import org.neo4j.dbms.api.DatabaseManagementService;
import org.neo4j.dbms.api.DatabaseManagementServiceBuilder;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.Transaction;

public class Embedded3 {
	private static final File databaseDirectory = new File(

	public String greeting;

	// tag::vars[]
	GraphDatabaseService graphDb;
	Node firstNode;
	Node secondNode;
	Relationship relationship;
	private DatabaseManagementService managementService;
	// end::vars[]

	// tag::createReltype[]
	private enum RelTypes implements RelationshipType {
	// end::createReltype[]

	public static void main(final String[] args) throws IOException {
		Embedded3 hello = new Embedded3();
		// hello.removeData();

	void createDb() throws IOException {
		// tag::startDb[]
		managementService = new DatabaseManagementServiceBuilder(databaseDirectory).build();
		graphDb = managementService.database("neo4j");
		try (Transaction tx = graphDb.beginTx()) {

			// Database operations go here
			firstNode = tx.createNode();
			firstNode.setProperty("message", "Hello, ");
			secondNode = tx.createNode();
			secondNode.setProperty("message", "World!");

			relationship = firstNode.createRelationshipTo(secondNode, RelTypes.KNOWS);
			relationship.setProperty("message", "brave Neo4j ");
			// end::addData[]

			greeting = ((String) firstNode.getProperty("message")) + ((String) relationship.getProperty("message"))
					+ ((String) secondNode.getProperty("message"));

			// tag::transaction[]

	void shutDown() {
		System.out.println("Shutting down database ...");
		// tag::shutdownServer[]
		// end::shutdownServer[]

	// tag::shutdownHook[]
	private static void registerShutdownHook(final DatabaseManagementService managementService) {
		// Registers a shutdown hook for the Neo4j instance so that it
		// shuts down nicely when the VM exits (even if you "Ctrl-C" the
		// running application).
		Runtime.getRuntime().addShutdownHook(new Thread() {
			public void run() {
	// end::shutdownHook[]

After, I have changed the value of dbms.default_database to dbms.default_database=new.db in neo4j.conf.

When I start neo4j, the database is well implemented:
Capture d’écran du 2020-09-02 09-33-19

But when I run a simple query MATCH (n) return n there is no record in the database to show.

Then I successfully created some nodes from the neo4j browser. But it's impossible to read them with my Java code, the database looks empty.

There must be an error in my code but I am really stucked right now.
Thanks for your help.


It seems like you are creating the database named neo4j not "new.db"

Thanks for you answer.
I tried to change this name by "new.db" and "new" but I always have a "DatabaseNotFoundException".
The problem must come from here.

In the code example given by Neo4j the DEFAULT_DATABASE_NAME is set to "neo4j".
I double checked and "new.db" is created whereas I set graphDb = managementService.database("neo4j");
I have a DatabaseNotFoundException if not.