If Java is your language of choice, the most popular drivers for Neo4j are:

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

Neo4j Bolt driver for Java

Neo4j Java Driver is the official Neo4j Java driver for connecting to Neo4j databases via Bolt (HTTP/HTTPS not available).

Driver web page: https://github.com/neo4j/neo4j-java-driver

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>1.0.4</version>
    </dependency>
</dependencies>

Check the driver releases for newest driver version available.

Connect to the to a GrapheneDB instance using the connection settings and create a dummy node:

import org.neo4j.driver.v1.*;

public class App 
{
  public static void main( String[] args )
  {
    Driver driver = GraphDatabase.driver( "bolt://hobby-geefdaeefcom.dbs.graphenedb.com:24786", AuthTokens.basic( "v303", "GtGq5rldxu" ) );

    Session session = driver.session();

    session.run("CREATE (n:Person {name:'Bob'})");
    StatementResult result = session.run("MATCH (n:Person) RETURN n.name AS name");

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

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

Neo4j OGM

Neo4j OGM is a library that allows you to use Object Graph Mapping from any Java or JVM-based application without requiring additional dependencies. It's also optimized for server-based installations utilizing Cypher via the transactional HTTP endpoint.

Neo4j OGM version 2.0.2 and higher also support the Bolt protocol.

Driver documentation page: https://github.com/neo4j/neo4j-ogm

Neo4j OGM projects can be built using Maven, Gradle or Ant/Ivy. You will find information for the other build tools in the driver manual. The following configuration is for a Maven application.

You will need to include dependencies entries for neo4j-ogm-core and the drivers you want to use in pom.xml file. If you’re not using a particular driver, you don’t need to declare it.

<dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-ogm-core</artifactId>
    <version>2.0</version>
</dependency>

<dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-ogm-http-driver</artifactId>
    <version>2.0</version>
</dependency>

<dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-ogm-bolt-driver</artifactId>
    <version>2.0</version>
</dependency>

Please note: If you are using Neo4j OGM 1.x, you only need to add the following dependency (Bolt protocol support is not available for this version):

<dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-ogm</artifactId>
    <version>2.0</version>
</dependency>

Check the driver releases for newest driver version available.

First, you will need to set up the domain entities of your application. See the driver documentation for more info.

Then you will need connect to the to a GrapheneDB instance. There are two basic ways to supply configuration information to OGM Neo4j: via a single properties file, or programmatically. Read more in this driver documentation section.

Using the properties file (ogm.properties). This file must be on the classpath.

With HTTP driver:

driver=org.neo4j.ogm.drivers.http.driver.HttpDriver
URI=http://hobby-geefdaeefcom.dbs.graphenedb.com:24789
username=v303
password=GtGq5rldxu

With Bolt driver:

driver=org.neo4j.ogm.drivers.bolt.driver.BoltDriver
URI=hobby-geefdaeefcom.dbs.graphenedb.com:24786
username=v303
password=GtGq5rldxu

Create a new session:

SessionFactory sessionFactory = new SessionFactory();

Using Java Configuration.

With HTTP driver:

Configuration configuration = new Configuration();
configuration.driverConfiguration()
  .setDriverClassName("org.neo4j.ogm.drivers.http.driver.HttpDriver")
  .setURI("http://hobby-geefdaeefcom.dbs.graphenedb.com:24789")
  .setCredentials("v303", "GtGq5rldxu");

// We pass it as the first argument to a SessionFactory instance
new SessionFactory(configuration, ...);

With Bolt driver:

Configuration configuration = new Configuration();
configuration.driverConfiguration()
  .setDriverClassName("org.neo4j.ogm.drivers.bolt.driver.BoltDriver")
  .setURI("bolt://hobby-geefdaeefcom.dbs.graphenedb.com:24786")
  .setCredentials("v303", "GtGq5rldxu");

// We pass it as the first argument to a SessionFactory instance
new SessionFactory(configuration, ...);

If you are using Neo4j OGM 1.x, simply pass the HTTP connection URL to the session object:

SessionFactory sessionFactory = new SessionFactory("org.neo4j.example.domain");
Session session = sessionFactory.openSession("http://v303:GtGq5rldxu@hobby-geefdaeefcom.dbs.graphenedb.com:24789");

Java