Get started
About the official Java driver
Neo4j provides official drivers for a number of popular programming languages. These drivers are supported by Neo4j.
Community drivers also exist for many languages, but vary greatly in terms of feature sets, maturity, and support. To find more about community drivers, visit https://neo4j.com/developer/language-guides/.
The following languages and frameworks are officially supported by Neo4j:
Language/framework | Versions supported |
---|---|
.NET |
|
Go |
|
Java |
Java 17. |
JavaScript |
|
Python |
Python 3.7 and above. |
The driver API is intended to be topologically agnostic. This means that the underlying database topology — single instance, Causal Cluster, etc. — can be altered without requiring a corresponding alteration to application code.
In the general case, only the connection URI needs to be modified when changes are made to the topology.
The official drivers do not support HTTP communication. If you need an HTTP driver, choose one of the community drivers. See also the HTTP API documentation. |
Driver versions and installation
Wherever possible, it is recommended to use the latest stable driver release available. This will provide the greatest degree of stability and will ensure that the full set of server functionality is available. The drivers, when used with Neo4j Enterprise Edition, come with full cluster routing support. The drivers make no explicit distinction between Enterprise Edition and Community Edition however, and simply operate with the functionality made available by Neo4j itself.
To use the Java driver, it is recommended employing a dependency manager, such as Maven or Gradle. To find the latest version of the driver, visit the Maven Central Repository.
Dependencies
-
org.reactivestreams:reactive-streams
-
org.apache.logging.log4j:log4j (optional)
The driver is dependent on the Reactive Streams API, thus maintaining JDK 8 compatibility. To make optimal use of the reactive APIs, we suggest an additional framework like Project Reactor or RxJava2. Both implement the Reactive Streams API and provide an exhaustive set of operators.
When using Maven, add the following block to the pom.xml file. The driver version can either be declared as a property (as in the first example) or as an explicit version number (as in the second).
<dependencies>
<dependency>
<groupId>org.neo4j.driver</groupId>
<artifactId>neo4j-java-driver</artifactId>
<version>$JAVA_DRIVER_VERSION</version>
</dependency>
</dependencies>
In the following example, driver version 5.12.0 is added.
<dependencies>
<dependency>
<groupId>org.neo4j.driver</groupId>
<artifactId>neo4j-java-driver</artifactId>
<version>5.12.0</version>
</dependency>
</dependencies>
For Gradle, a compile line will be required. Again, this can use a property or an explicit version number.
compile 'org.neo4j.driver:neo4j-java-driver:$JAVA_DRIVER_VERSION'
In the following example, a driver version 5.12.0 is added.
compile 'org.neo4j.driver:neo4j-java-driver:5.12.0'
The release notes for this driver are available here.
A "Hello World" example
The example below shows the minimal configuration necessary to interact with Neo4j through the Java driver:
import org.neo4j.driver.AuthTokens;
import org.neo4j.driver.Driver;
import org.neo4j.driver.GraphDatabase;
import org.neo4j.driver.Query;
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));
}
@Override
public void close() throws RuntimeException {
driver.close();
}
public void printGreeting(final String message) {
try (var session = driver.session()) {
var greeting = session.executeWrite(tx -> {
var query = new Query("CREATE (a:Greeting) SET a.message = $message RETURN a.message + ', from node ' + id(a)", parameters("message", message));
var result = tx.run(query);
return result.single().get(0).asString();
});
System.out.println(greeting);
}
}
public static void main(String... args) {
try (var greeter = new HelloWorldExample("bolt://localhost:7687", "neo4j", "password")) {
greeter.printGreeting("hello, world");
}
}
}
Driver API docs
For a comprehensive listing of all driver functionality, please see the Java API reference documentation.