Skip to content

neo4j-contrib/neo4j-jdbc

5.0
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

Bumps [org.apache.maven.plugins:maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.5.0 to 3.5.1.
- [Release notes](https://github.com/apache/maven-shade-plugin/releases)
- [Commits](apache/maven-shade-plugin@maven-shade-plugin-3.5.0...maven-shade-plugin-3.5.1)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-shade-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
95a90c0

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Overview: Neo4j JDBC Driver

CI

You can find the full documentation at: http://neo4j-contrib.github.io/neo4j-jdbc/

This is a JDBC driver for Neo4j supporting Cypher over JDBC.

This driver was mainly developed by Larus BA, Italy, a certified consulting and integration solutions partner for Neo4j. Thank you so much for all your work.

Being a graph database, Neo4j is not serving data in a relational way, nevertheless thanks to this driver it’s possible for projects that are using the classic JDBC connector in the relational paradigm to interact with Neo4j.

Download

Simply add the JDBC dependency to your project:

<dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-jdbc-bolt</artifactId>
    <version>{neo4j-jdbc-version}</version>
    <scope>runtime</scope>
</dependency>

Transport support

From 5.0 onwards, this driver supports only the Bolt protocol, through:

  • The Bolt direct connection protocol using jdbc:neo4j:bolt://<host>:<port>/

  • The Bolt routing-aware protocol for clusters using jdbc:neo4j:neo4j://<host>:<port>/

You can also specify the encryption via the Bolt URI scheme:

  • jdbc:neo4j:bolt://<host>:<port>/

  • jdbc:neo4j:bolt+s://<host>:<port>/

  • jdbc:neo4j:bolt+ssc://<host>:<port>/

  • jdbc:neo4j:neo4j://<host>:<port>/

  • jdbc:neo4j:neo4j+s://<host>:<port>/

  • jdbc:neo4j:neo4j+ssc://<host>:<port>/

See the official Neo4j Java driver documentation to learn more.

Minimum viable snippet

Dependency declaration
org.neo4j:neo4j-jdbc-bolt:5.0.0
Run Query
// Connecting
try (Connection connection = DriverManager.getConnection("jdbc:neo4j:bolt://localhost", "neo4j", password);
    // Querying
     PreparedStatement stmt = connection.prepareStatement("MATCH (u:User)-[:FRIEND]-(f:User) WHERE u.name = $0 RETURN f.name, f.age")) {

    stmt.setString(0, "John");

    try (ResultSet rs = stmt.executeQuery()) {
        while (rs.next()) {
            System.out.println("Friend: "+rs.getString("f.name")+" is "+rs.getInt("f.age"));
        }
    }
}

Configuration

Property Name Supported Values Description

trust.strategy

TRUST_ALL_CERTIFICATES, TRUST_CUSTOM_CA_SIGNED_CERTIFICATES, TRUST_SYSTEM_CA_SIGNED_CERTIFICATES

The supported trusted strategies

trusted.certificate.file

File Path

The path of the certificate file

connection.acquisition.timeout

Any Long

The acquisition time

connection.liveness.check.timeout

Any Long

The liveness check timeout

connection.timeout

Any Long

The connection timeout

encryption

true/false

Activate the application encryption

leaked.sessions.logging

true/false

If log leaked session

max.connection.lifetime

Any Long

The connection lifetime

max.connection.poolsize

Any Int

The max pool size

max.transaction.retry.time

Any Long

The retry time for a transaction transient error

database

String

The database name, if not specified connects to the default instance

readonly

true/false

If specified creates a fixed read only connection, any further modification via the Connection#setReadOnly method will have no effect

autocommit

true/false

If specified sets the autocommit property as initial value, you can still change the autocommit value by using Connection#setAutoCommit method, but it will have effect only for newly created transactions

usebookmarks

true/false

If specified disables the bookmarks

Flattening

As most JDBC clients and tools don’t support complex objects, the driver can flatten returned nodes and relationships by providing all their properties as individual columns with names like u.name,r.since if you just return a node u or relationship r.

This is enabled with the JDBC-URL parameter flatten=<rows>, where <rows> indicates how many rows are sampled to determine those columns. With -1 all rows are sampled and with any other value you determine the number of rows being looked at.

Tomcat

When the JDBC driver is configured as a JNDI resource into Tomcat, you must include these two arguments on Resource configuration:

  • removeAbandonedOnBorrow="true"

  • closeMethod="close"

Here’s an example:

    <Resource name="jdbc/neo4j"
              auth="Container"
              type="javax.sql.DataSource"
              username="neo4j"
              password="password"
              driverClassName="org.neo4j.jdbc.bolt.BoltDriver"
              url="jdbc:neo4j:bolt://localhost"
              removeAbandonedOnBorrow="true"
              closeMethod="close"
              />

Building the driver yourself

First clone the repository.

This project is composed by the following modules:

Run all unit tests & integration tests
mvn clean test
Run only integration tests
mvn clean test -Pintegration-test
Run performance tests
mvn clean test -Pperformance-test
Note
To run the performance test, you must have a Neo4j Server running with the Bolt protocol enabled on port 7687 (default).

License

Copyright (c) Neo4j and LARUS Business Automation

The "Neo4j JDBC Driver" is licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.

You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and limitations under the License.

Feedback

Please provide feedback and report bugs as GitHub issues or join Neo4j Discord. You may also post questions on Neo4j Community or StackOverflow with the neo4j and jdbc tags.