Java is one of the Neo4j supported languages and an official driver is provided. Official drivers connect to the databases using BOLT protocol (HTTP is not available).

🚧

We are working on supporting Neo4j 4.1 drivers. Please use 4.0 in the meantime.

📘

About connection parameters

We've used test credentials for all the following examples. Please replace them with your real connection parameters.

You'll find all the required information to connect to your database on our admin panel if you navigate to the Connection section. More on connecting to your database here

This section is intended to provide a small working example to connect to a GrapheneDB database using the Java driver. To get more detailed information, visit the driver web page: http://neo4j.com/docs/api/javascript-driver/current/

📘

Bolt protocol is only available in 3.0.0 or higher versions of Neo4j. You can check your Neo4j version if you navigate to the Overview page of your database.

The following example is a Maven application that just uses the driver to write and read a node.

Include Neo4j Java Driver in your dependencies in pom.xml file:

<dependencies>
  <dependency>
    <groupId>org.neo4j.driver</groupId>
    <artifactId>neo4j-java-driver</artifactId>
    <version>4.0.1</version>
  </dependency>
</dependencies>

📘

Check the driver releases for newest driver version available.

🚧

In the last version of Neo4j drivers the default configuration for encrypted option is now false. Since GrapheneDB only accepts encrypted connections, please ensure encryption is active.

Connect to the to a GrapheneDB instance using the connection settings and run a simple query of the Movies dataset example:

import org.neo4j.driver.*;

public class App 
{
  public static void main( String[] args )
  {
    Config.ConfigBuilder builder = Config.builder().withEncryption();
    Config config = builder.build();

    Driver driver = GraphDatabase.driver("bolt://db-jidgsytyxo1r31sd4ker.graphenedb.com:24786", AuthTokens.basic( "admin", "b.P0shGn2gvpUD.9RAHyuY4QXkkUK7w" ), config);

    Session session = driver.session();

    Result result = session.run("MATCH (:Person {name: 'Tom Hanks'})-[:ACTED_IN]->(movies) RETURN movies.title AS title");

    while ( result.hasNext() )
    {
      Record record = result.next();
      System.out.println( record.get("title").asString() );
    }

    session.close();
    driver.close();
  }
}

You can also use the new bolt+s URI scheme to enable encryption with a full certificate check:

Driver driver = GraphDatabase.driver("bolt://db-jidgsytyxo1r31sd4ker.graphenedb.com:24786", AuthTokens.basic( "admin", "b.P0shGn2gvpUD.9RAHyuY4QXkkUK7w" ));

Updated about a month ago

Java


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.