Developer Guides Getting Started Getting Started What is a Graph Database? Intro to Graph DBs Video Series Concepts: RDBMS to Graph Concepts: NoSQL to Graph Getting Started Resources Neo4j Graph Platform Graph Platform Overview Neo4j Desktop Intro Neo4j Browser Intro… Read more →

Developer Guides

Want to Speak? Get $ back.

Using Neo4j from Java

If you are a Java developer, this guide provides an overview of options for connecting to Neo4j. While this guide is not comprehensive, it will introduce the different APIs and link to the relevant resources.
You should be familiar with the graph database concepts and the property graph model. Having installed Neo4j and tried out our Cypher Query language helps too. When developing with Neo4j, please use Java 8 or 11 and your favorite IDE.

Neo4j for Java Developers


Neo4j offers a rich set of integration possibilities for developers using Java or other JVM-languages.

The standalone Neo4j Server can be installed on any machine and then accessed via its binary “Bolt” protocol through our official driver or any bolt-enabled drivers.

You can also extend Neo4j by implementing user defined procedures for Cypher in Java or other JVM languages.

Please note the minimum version compatibilities:
Neo4j Server 3.x – Java 8
Neo4j Server 4.x – Java 11

The Example Project

The Neo4j example project is a small, one page webapp for the movies database built into the Neo4j tutorial. The front-end page is the same for all drivers: movie search, movie details, and a graph visualization of actors and movies. Each backend implementation shows you how to connect to Neo4j from each of the different languages and drivers.

You can learn more about our small, consistent example project across many different language drivers here. You will find the implementations for all drivers as individual GitHub repositories, which you can clone and deploy directly.

Neo4j Java Driver

The Neo4j Java driver is officially supported by Neo4j and connects to the database using the binary protocol. It aims to be minimal, while being idiomatic to Java. We support Java 8 and 11 for the driver.

When using Maven, add this to your pom.xml file:


For Gradle or Grails, this is how to add the dependency:

compile 'org.neo4j.driver:neo4j-java-driver:4.0.0'

For other build systems, see information available at Maven Central.

import org.neo4j.driver.AuthTokens;
import org.neo4j.driver.Driver;
import org.neo4j.driver.GraphDatabase;
import org.neo4j.driver.Session;
import org.neo4j.driver.Result;
import org.neo4j.driver.Transaction;
import org.neo4j.driver.TransactionWork;

import static org.neo4j.driver.Values.parameters;

public class HelloWorldExample implements AutoCloseable
    private final Driver driver;

    public HelloWorldExample( String uri, String user, String password )
        driver = GraphDatabase.driver( uri, AuthTokens.basic( user, password ) );

    public void close() throws Exception

    public void printGreeting( final String message )
        try ( Session session = driver.session() )
            String greeting = session.writeTransaction( new TransactionWork<String>()
                public String execute( Transaction tx )
                    Result result = "CREATE (a:Greeting) " +
                                                     "SET a.message = $message " +
                                                     "RETURN a.message + ', from node ' + id(a)",
                            parameters( "message", message ) );
                    return result.single().get( 0 ).asString();
            } );
            System.out.println( greeting );

    public static void main( String... args ) throws Exception
        try ( HelloWorldExample greeter = new HelloWorldExample( "bolt://localhost:7687", "neo4j", "password" ) )
            greeter.printGreeting( "hello, world" );






The Neo4j Team



Neo4j Online Community