== Overview: Neo4j JDBC Driver :neo4j-jdbc-version: 3.2.0
ifndef::env-docs[] image:https://travis-ci.org/neo4j-contrib/neo4j-jdbc.svg?branch=master["Build Status", link="https://travis-ci.org/neo4j-contrib/neo4j-jdbc"]
You can find the full documentation at: http://neo4j-contrib.github.io/neo4j-jdbc/ endif::env-docs[]
This is the official JDBC driver for Neo4j.
This driver was mainly developed by http://larus-ba.it[Larus BA, Italy], a certified consulting and integration solutions partner for Neo4j. Thank you so much for all your work.
[NOTE] The previous JDBC driver for Neo4j 2.x was moved to the https://github.com/neo4j-contrib/neo4j-jdbc-2x repository.
Being a graph database, Neo4j is not serving data in a relational way and the exact purpose of this project is to allow projects that are using the classic JDBC connector in the relational paradigm to interact with Neo4j.
This driver supports various types of database transports:
jdbc:neo4j:bolt://<host>:<port>/
jdbc:neo4j:http://<host>:<port>/
Going forward there will also be support for:
=== Maven dependency
For the all-in-one module supporting both Bolt and HTTP, you can simply use:
[source,xml]
If you only want one of the protocols, you can depend on its module:
[source,xml]
or
[source,xml]
=== Minimum viable snippet
// tag::mvs[]
// Connecting try (Connection con = DriverManager.getConnection("jdbc:neo4j:bolt://localhost", 'neo4j', password)) {
// Querying
String query = "MATCH (u:User)-[:FRIEND]-(f:User) WHERE u.name = {1} RETURN f.name, f.age";
try (PreparedStatement stmt = con.prepareStatement(query)) {
stmt.setString(1,"John");
try (ResultSet rs = stmt.execute()) {
while (rs.next()) {
System.out.println("Friend: "+rs.getString("f.name")+" is "+rs.getInt("f.age"));
}
}
}
// end::mvs[]
Please note that the example above uses the try-with-resource blocks that automatically closes resources when the try
block is exited.
=== Usage with Neo4j Server
Install a Neo4j 3.2.x server and start it with the Bolt protocol enabled
Connect with URLs in the form jdbc:neo4j:bolt://<host>:<port>/
(e.g. jdbc:neo4j:bolt://localhost/
)
You can also use additional comma separated parameters in the URL for authentication, debug mode, SSL encryption and flattening e.g. jdbc:neo4j:bolt://localhost/?user=neo4j,password=xxxx,debug=true,nossl,flatten=[-1,100,1000]
Add the JDBC driver dependency or jar file to your project
Get a connection from DriverManager
Execute queries and transactions using the Cypher graph query language
=== 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.
=== Building the driver yourself
First clone https://github.com/neo4j-contrib/neo4j-jdbc[the repository].
This project is composed by the following modules:
[NOTE] To run the performance test, you must have a Neo4j Server 3.2.x running with the Bolt protocol enabled on port 7687 (default)
=== License
Copyright (c) 2017 http://neo4j.com[Neo4j] and http://www.larus-ba.it[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
https://www.apache.org/licenses/LICENSE-2.0
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 link:./issues[GitHub issues] or join the http://neo4j.com/slack[neo4j-users Slack] and ask on the #neo4j-jdbc channel.
You might also ask on http://stackoverflow.com/questions/tagged/neo4j+jdbc[StackOverflow], please tag your question there with neo4j
and jdbc
.