Neo4j Driver Java Skill logo

Neo4j Driver Java Skill

Organization
neo4j-contrib
neo4j-driver-java-skill

Neo4j Java Driver v6 — driver lifecycle, Maven/Gradle setup, executableQuery, executeRead/Write managed transactions, explicit transactions, async/reactive patterns, error handling, data type mapping, connection pool tuning, causal consistency/bookmarks. Use when writing Java or Kotlin code that connects to Neo4j via GraphDatabase.driver, executableQuery, SessionConfig, executeRead, executeWrite, or TransactionCallback. Does NOT handle Cypher authoring — use neo4j-cypher-skill. Does NOT cover driver version upgrades — use neo4j-migration-skill. Does NOT cover Spring Data Neo4j (@Node, Neo4jRepository) — use neo4j-spring-data-skill.

Overview

Publisherneo4j-contrib
Repositoryneo4j-skills
Skill nameneo4j-driver-java-skill
Stars
112
Forks
38
Bundled files
2
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 2 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by neo4j-contrib on GitHub. Read the source before you install it.

Installation

Install the Neo4j Driver Java Skill AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/neo4j-contrib/neo4j-skills.git /tmp/neo4j-skills
mkdir -p .claude/skills
cp -r /tmp/neo4j-skills/neo4j-driver-java-skill .claude/skills/neo4j-driver-java-skill
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Neo4j Driver Java Skill in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Neo4j Driver Java Skill on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Neo4j Driver Java Skill is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

When to Use

  • Java/Kotlin code connecting to Neo4j (Aura or self-managed)
  • Setting up driver, sessions, transactions in Maven/Gradle projects
  • Debugging result handling, error recovery, connection pool issues
  • Async (CompletableFuture) or reactive (Project Reactor / RxJava) Neo4j access

When NOT to Use

  • Cypher query authoring/optimizationneo4j-cypher-skill
  • Driver version upgradesneo4j-migration-skill
  • Spring Data Neo4j (@Node, @Relationship, Neo4jRepository) → neo4j-spring-data-skill

Dependency

Maven

xml
<dependency>
    <groupId>org.neo4j.driver</groupId>
    <artifactId>neo4j-java-driver</artifactId>
    <version>6.2.1</version>
</dependency>

Gradle

groovy
implementation 'org.neo4j.driver:neo4j-java-driver:6.2.1'

Check latest: https://central.sonatype.com/artifact/org.neo4j.driver/neo4j-java-driver

6.2.0 [2026-06]: Neo4j UUID type + Bolt 6.1 support; QueryProfile in result summary. 6.2.1 [2026-08]: fixes Value#asObject() on UUID values — required if reading UUID properties generically. Neo4j 2026.08 server bundles 6.2.1; 2026.07 bundles 6.2.0.

Server-side UUID type and uuid() constructors ship in Neo4j 2026.08 — use driver >= 6.2.1 against those servers.


Environment Variables

Standard pattern for connection config — never hardcode credentials:

java
String uri      = System.getenv().getOrDefault("NEO4J_URI",      "neo4j://localhost:7687");
String user     = System.getenv().getOrDefault("NEO4J_USERNAME",  "neo4j");
String password = System.getenv().getOrDefault("NEO4J_PASSWORD",  "");
String database = System.getenv().getOrDefault("NEO4J_DATABASE",  "neo4j");

Spring Boot: inject via @Value("${spring.neo4j.uri}") or application.properties:

properties
spring.neo4j.uri=neo4j+s://xxx.databases.neo4j.io
spring.neo4j.authentication.username=neo4j
spring.neo4j.authentication.password=secret

Driver Lifecycle

One Driver per application — thread-safe, expensive to create. Implement AutoCloseable or use try-with-resources.

java
// Long-lived singleton
var driver = GraphDatabase.driver(
    "neo4j+s://xxx.databases.neo4j.io",          // Aura TLS+routing
    AuthTokens.basic(user, password));
driver.verifyConnectivity();                      // fail fast

// Short-lived (tests / CLI)
try (var driver = GraphDatabase.driver(uri, AuthTokens.basic(user, password))) {
    driver.verifyConnectivity();
    // ...
}

URI schemes:

URIUse
neo4j://localhostUnencrypted, cluster routing
neo4j+s://xxx.databases.neo4j.ioTLS + cluster routing (Aura)
bolt://localhost:7687Unencrypted, single instance
bolt+s://localhost:7687TLS, single instance

Auth options: AuthTokens.basic(u,p) · AuthTokens.bearer(token) · AuthTokens.kerberos(b64) · AuthTokens.none()


Choosing the Right API

APIWhenAuto-retryStreaming
driver.executableQuery()Default for most queries❌ eager
session.executeRead/Write()Large results, callback control
session.beginTransaction()Multi-method, external coordination
session.run()Self-managing queries (CALL IN TRANSACTIONS)⚠️ one-shot [6.1+]
driver.asyncSession()Non-blocking CompletableFuture
driver.rxSession()Reactor/RxJava backpressure

CALL { … } IN TRANSACTIONS and USING PERIODIC COMMIT self-manage their transaction — use session.run() only. executableQuery and executeRead/Write will fail for these queries.

session.run() retry [6.1+]: single immediate retry on idempotent errors only (enabled by default). Disable per driver or per session:

java
// Driver-level — disable for all sessions
var config = Config.builder().withAutoCommitRetriesDisabled(true).build();

// Session-level — overrides driver
var sessionConfig = SessionConfig.builder()
    .withAutoCommitRetriesMode(AutoCommitRetriesMode.DISABLED)  // DEFAULT = follow driver
    .build();

executableQuery — Default

java
// Read — route to replicas
var result = driver.executableQuery("""
        MATCH (p:Person {name: $name})-[:KNOWS]->(friend)
        RETURN friend.name AS name
        """)
    .withParameters(Map.of("name", "Alice"))
    .withConfig(QueryConfig.builder()
        .withDatabase("neo4j")            // always specify — avoids home-db round-trip
        .withRouting(RoutingControl.READ)
        .build())
    .execute();

result.records().forEach(r -> System.out.println(r.get("name").asString()));
long ms = result.summary().resultAvailableAfter(TimeUnit.MILLISECONDS);

// Write
driver.executableQuery("CREATE (p:Person {name: $name, age: $age})")
    .withParameters(Map.of("name", "Bob", "age", 30))
    .withConfig(QueryConfig.builder().withDatabase("neo4j").build())
    .execute();

Never string-interpolate Cypher. Always .withParameters(Map.of(...)).


Managed Transactions (executeRead / executeWrite)

Sessions are NOT thread-safe — one per request/thread, always close.

java
try (var session = driver.session(SessionConfig.builder()
        .withDatabase("neo4j").build())) {

    // Read → replica routing
    var names = session.executeRead(tx -> {
        var result = tx.run(
            "MATCH (p:Person) WHERE p.name STARTS WITH $prefix RETURN p.name AS name",
            Map.of("prefix", "Al"));
        return result.stream().map(r -> r.get("name").asString()).toList(); // collect INSIDE
    });

    // Write → leader routing
    session.executeWriteWithoutResult(tx ->
        tx.run("CREATE (p:Person {name: $name})", Map.of("name", "Carol"))
    );
}

Result must be consumed INSIDE the callback

Result is a lazy cursor tied to the open transaction. Transaction closes when callback returns — any read after that throws ResultConsumedException.

java
// ❌ Returns Result — already closed by the time caller uses it
var result = session.executeRead(tx ->
    tx.run("MATCH (p:Person) RETURN p.name AS name"));
result.stream().forEach(...); // throws ResultConsumedException

// ✅ Collect to List inside callback
var names = session.executeRead(tx ->
    tx.run("MATCH (p:Person) RETURN p.name AS name")
      .stream().map(r -> r.get("name").asString()).toList());

Callback rules

  • Consume each Result before next tx.run() — multiple open cursors = undefined behaviour.
  • No side effects (HTTP, email, metric increments) — callback may be retried on transient errors.
  • Use MERGE (idempotent), not CREATE, for retry-safe writes.
  • executeRead → replica; executeWrite → leader.

TransactionConfig — timeouts & metadata

java
var config = TransactionConfig.builder()
    .withTimeout(Duration.ofSeconds(5))
    .withMetadata(Map.of("app", "myService", "user", userId))  // visible in SHOW TRANSACTIONS
    .build();
session.executeRead(tx -> { /* ... */ }, config);

Explicit Transactions

Use when work spans multiple methods or requires external coordination. Not auto-retried.

java
try (var session = driver.session(SessionConfig.builder().withDatabase("neo4j").build())) {
    var tx = session.beginTransaction();
    try {
        doPartA(tx);
        doPartB(tx);
        tx.commit();
    } catch (Exception e) {
        try { tx.rollback(); } catch (Exception rb) { e.addSuppressed(rb); }
        throw e;
    }
}

tx.rollback() is a network call — wrap in its own try/catch and use addSuppressed so the original exception is not lost.

Commit uncertainty: if tx.commit() throws ServiceUnavailableException, the commit may or may not have succeeded. Design writes as idempotent (MERGE + unique constraints) so retrying is safe.

Choose explicit vs managed:

  • Auto-retry needed → executeRead / executeWrite
  • Work spans multiple methods → explicit (pass tx as parameter)
  • Coordinating with external I/O → explicit (commit only after I/O succeeds)

Error Handling

java
try {
    driver.executableQuery("...").execute();
} catch (ServiceUnavailableException e) {
    // No servers — check connection
} catch (SessionExpiredException e) {
    // Server closed session — open new one
} catch (TransientException e) {
    // Managed txns retry automatically; explicit txns need manual retry
} catch (Neo4jException e) {
    // Cypher/constraint error — e.code() gives GQL status code
}

Managed transactions auto-retry TransientException — no catch needed.


Data Types & Value Extraction

Cypher typeJava accessor
Integervalue.asLong() / value.asInt()
Floatvalue.asDouble()
Stringvalue.asString()
Booleanvalue.asBoolean()
Listvalue.asList()
Mapvalue.asMap()
Nodevalue.asNode()
Relationshipvalue.asRelationship()
Datevalue.asLocalDate()
DateTimevalue.asZonedDateTime()
UUIDvalue.asUUID()java.util.UUID [6.2+, Neo4j 2026.08+]
java
var record = result.records().get(0);
String name = record.get("name").asString();
long age    = record.get("age").asLong();

var node = record.get("p").asNode();
String label = node.labels().iterator().next();
Map<String,Object> props = node.asMap();

Null safety — two distinct cases

Situationrecord.get(key).asString()
Key present, value non-nullthe valuereturns string
Key present, value is graph nullValue where .isNull() = truethrows Uncoercible
Key absent (typo / not projected)Value.NULL sentinelthrows NoSuchElementException
java
// Graph null — use default overload (safe only if key is always projected):
String city = record.get("city").asString("Unknown");

// Absent key — check containsKey first:
if (record.containsKey("city") && !record.get("city").isNull()) {
    String city = record.get("city").asString();
}

Object Mapping

Map query results to Java records/classes directly — eliminates manual accessor calls.

java
// Domain record — field names match RETURN aliases (case-sensitive)
public record Person(String name, long age) {}

// Map single record
var person = driver.executableQuery("MATCH (p:Person {name: $name}) RETURN p.name AS name, p.age AS age")
    .withParameters(Map.of("name", "Alice"))
    .withConfig(QueryConfig.builder().withDatabase("neo4j").build())
    .execute()
    .records()
    .stream()
    .map(r -> r.get("name").asString())   // or: r.as(Person.class) — see note
    .findFirst()
    .orElseThrow();

// Using .as(Person.class) — maps RETURN keys to record fields by name
var person2 = driver.executableQuery("""
        MATCH (p:Person {name: $name})
        RETURN p.name AS name, p.age AS age
        """)
    .withParameters(Map.of("name", "Tom Hanks"))
    .withConfig(QueryConfig.builder().withDatabase("neo4j").build())
    .execute()
    .records()
    .stream()
    .map(record -> record.get("p").as(Person.class))
    .findFirst()
    .orElseThrow(() -> new RuntimeException("Person not found"));

Nested mapping — return a map projection and include COLLECT {} for lists:

java
public record Movie(String title, List<Person> actors) {}

var movieCypher = """
    MATCH (movie:Movie)
    LIMIT 1
    RETURN movie {
        .title,
        actors: COLLECT {
            MATCH (actor:Person)-[:ACTED_IN]->(movie)
            RETURN actor
        }
    }
    """;

var movie = driver.executableQuery(movieCypher)
    .withConfig(QueryConfig.builder().withDatabase("neo4j").build())
    .execute()
    .records()
    .stream()
    .map(r -> r.get("movie").as(Movie.class))
    .findFirst()
    .orElseThrow();

Only mapped properties defined in the record are populated — extra properties returned by Cypher are ignored.


Performance Patterns

Always specify database — omitting triggers home-db round-trip on every call.

Route reads to replicasRoutingControl.READ in QueryConfig or use executeRead.

Batch writes with UNWIND — pass List<Map<String,Object>> (plain maps only; custom objects fail):

java
List<Map<String, Object>> rows = people.stream()
    .map(p -> Map.<String, Object>of("name", p.name(), "age", p.age()))
    .toList();

driver.executableQuery("UNWIND $items AS item MERGE (p:Person {name: item.name}) SET p.age = item.age")
    .withParameters(Map.of("items", rows))
    .withConfig(QueryConfig.builder().withDatabase("neo4j").build())
    .execute();

Allowed leaf types in parameter maps: String, Long/Integer/Short/Byte, Double/Float, Boolean, List<?>, Map<String,?>, null. Custom objects and LocalDate must be converted first.

Group writes in one transaction — one executeWrite with a loop, not one executeWrite per iteration.

Connection pool — default 100 connections. Tune if exhausted:

java
Config.builder()
    .withMaxConnectionPoolSize(50)
    .withConnectionAcquisitionTimeout(30, TimeUnit.SECONDS)
    .build()

Common Errors

MistakeFix
String-interpolate Cypher params.withParameters(Map.of(...)) always
Omit database nameSet in QueryConfig / SessionConfig every time
New Driver per requestCreate once at startup; share everywhere
Share Session across threadsOne session per request/thread
Return Result from tx callbackCollect to List/Map inside callback
Leave Result open before next tx.run()Consume before next call
Side effects in managed tx callbackMove outside — callback may retry
Pass custom objects to UNWIND paramsConvert to List<Map<String,Object>>
asString() on graph null.asString("default") or check .isNull()
asString() on absent keycontainsKey() before optional access
Naked tx.rollback() in catchWrap in try/catch; use addSuppressed
Assume commit() failure = no commitCommit uncertainty — design writes idempotent
Block inside async callback (.join())Chain with thenCompose
Skip session close in async error pathexceptionallyCompose to close then re-throw
One transaction per write in loopBatch with UNWIND or group in one callback
executeWrite for a readUse executeRead — routes to replica

References

Load on demand:

  • references/async-reactive.md — full async CompletableFuture patterns, reactive RxSession with Flux.usingWhen, deadlock avoidance
  • references/advanced-config.md — full Config.builder() options, TLS, notification filtering, session-level auth, user impersonation, cross-session bookmarks, spatial types (Values.point/WGS-84/Cartesian)

Docs:


Checklist

  • One Driver instance created at startup; closed on shutdown
  • verifyConnectivity() called after driver creation
  • Database name specified in every QueryConfig / SessionConfig
  • Parameters used (never string-interpolated Cypher)
  • Result consumed inside managed transaction callback
  • No side effects inside executeRead/Write callbacks
  • Sessions closed via try-with-resources
  • Async sessions closed in both success and error paths (exceptionallyCompose)
  • ServiceUnavailableException on commit handled as commit-uncertain
  • UNWIND params are List<Map<String,Object>> (no custom objects)
  • containsKey() checked before accessing optional result columns

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Neo4j Driver Java Skill AI skill do?

Neo4j Java Driver v6 — driver lifecycle, Maven/Gradle setup, executableQuery, executeRead/Write managed transactions, explicit transactions, async/reactive patterns, error handling, data type mapping, connection pool tuning, causal consistency/bookmarks. Use when writing Java or Kotlin code that connects to Neo4j via GraphDatabase.driver, executableQuery, SessionConfig, executeRead, executeWrite, or TransactionCallback. Does NOT handle Cypher authoring — use neo4j-cypher-skill. Does NOT cover driver version upgrades — use neo4j-migration-skill. Does NOT cover Spring Data Neo4j (@Node, Neo4j...

Why use Neo4j Driver Java Skill on TypingMind?

Because you install it once and use it with any model. Neo4j Driver Java Skill is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Neo4j Driver Java Skill in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/neo4j-contrib/neo4j-skills/tree/main/neo4j-driver-java-skill. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Neo4j Driver Java Skill?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Neo4j Driver Java Skill?

As many as you like. As long as a model supports skills, you can use Neo4j Driver Java Skill with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Neo4j Driver Java Skill AI skill free?

Yes. It is published on GitHub by neo4j-contrib under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇