Neo4j JDBC Driver 3.0.3 & 3.1.0 Released


[As community content, this post reflects the views and opinions of the particular author and does not necessarily reflect the official stance of Neo4j.]

Click here to skip straight to the JDBC driver announcement.

During his opening keynote address, Emil Eifrem – CEO of Neo4j – called GraphConnect Europe “my favorite day of the year.” Without a doubt, this is true for all of the graph-addicted living in Europe, including Neo4j partners like us. At LARUS, we actually call it “THE Conference!”.

Year after year, more and more IT experts (developers, architects, database administrators and managers) are attending the conference and also the number of talks is incredibly growing. This year they were organized in four tracks, just confirming how many companies are using graph database to deliver their solutions with success.

And don’t forget all of the collateral events: the day before there were a lot of trainings (from Fundamentals to Graph Data Modeling and Neo4j in Production) and the lovely evening hackathon, this time centered around the theme of data journalism (also to celebrate the Pulitzer Prize recently awarded to the ICIJ for the Panama Papers investigation).

But for us Partners this is also an important occasion to join our long-term friends and work on the projects we’re contributing to with the Neo4j core team – finally face-to-face :-).

Integrate Neo4j with All the Things


As a Neo4j integrator leader, LARUS specializes in building any required connector for most of the products and solutions already adopted by our customers: BI or Reporting tools, other NoSQL databases, libraries, frameworks, ETL tools, etc.

In fact, we love to help customers to embrace Neo4j as easily and happily as possible while at the same time taking care of their existing IT ecosystem and architecture (such as banks, telecom providers, governments and retailers).

At this year’s GraphConnect Europe, Omar Rampado CTO at LARUS, presented a brand-new version of our Couchbase-Neo4j Connector, now renamed Doc2Graph since it now works with MongoDB and any generic JSON API as well.

If you’re interested, the Community Edition is available on our GitHub for free.

Besides its own integration projects, LARUS also officially contributes to many Neo4j projects. As coordinated by Michael Hunger – Neo4j Community Caretaker-General and creator of many neo4j-contrib projects – we are currently working on:

The Neo4j JDBC Driver


In particular, LARUS is the official developer and maintainer of the Neo4j JDBC Driver.

Sun Microsystems released JDBC as part of Java Development Kit (JDK) 1.1 on February 19, 1997 and 20 years later, the vast majority of products, solutions, tools, frameworks and IDEs use a JDBC Driver in order to connect with an underlying database.

That’s why in January 2016 we started implementing a brand-new version of the Neo4j JDBC Driver that allows any Java application to run Cypher queries against Neo4j via the standard JDBC API.

Compared with its previous 2.x version, this driver comes with two major benefits:
    • The Bolt binary protocol: introduced since Neo4j 3.0 to speedup performances
    • Modularization: HTTP and Bolt protocols are available both as an “all-in” package and as two separated jars (minimizing this way the specific driver size, by skipping unnecessary dependencies for unwanted protocols).

Two New Releases, 3.0.3 & 3.1.0, Are Now Available


In London, I luckily met Konstantin Lutovich from the official Java Bolt Driver team, and he patiently explained to me all the details about the new 1.3 version. With his support, we successfully updated the Neo4j JDBC Driver in order to make use of this latest Java Bolt Driver release 1.3 and together with Michael Hunger we finally released two new versions of it:
  1. Neo4j JDBC Driver v. 3.0.3, working with Neo4j 3.0.x
  2. Neo4j JDBC Driver v. 3.1.0, the first release working with Neo4j 3.1.x
They both contain the following fixes and updates:
    • Update to Neo4j 3.0.9 (or 3.1.4 respectively)
    • Makes use of the latest neo4j-java-driver version 1.3.0
    • Makes use of the latest http-client version 4.5.3
    • Makes use of the latest jackson version 2.8.8
    • Only shades the neo4j-jdbc-driver project instead of the two neo4j-jdbc-bolt and neo4j-jdbc-http modules (not shaded)
    • Corrected bug that switched to non-autocommit mode when there was an error
    • Improvement on BoltDatabaseMetaData
    • Better alignment of BoltStatement.execute with BoltPreparedStatement.execute
    • BoltDatabaseMetadata.getTables implementation returning Labels list
    • Mybatis example added
    • fix, int and float conversion to string
    • ResultSet.getInt/Long/Float/Double now return 0 for NULL values
    • ResultSet.getBoolean returns false for NULL values

Start Using the JDBC Driver for Neo4j in 5 Minutes


  1. Download the installation package Neo4j JDBC Driver 3.0.3 for Neo4j 3.0.x (here) or Neo4j JDBC Driver 3.1.0 for Neo4j 3.1.x (here).

    Please notice that these two jars are shaded, which means that all the dependencies are nested inside. In case you have version conflicts with your application’s dependencies then you can use the not-shaded versions:

    Bolt 3.0.3 (here) or 3.1.0 (here)
    HTTP 3.0.3 (here) or 3.1.0 (here)

  2. Configure the connection. The JDBC Driver for Neo4j can be used with any Cypher query or reporting software that supports JDBC. The connection information is:

    • JDBC Driver class names (automatically registered):
      Generic : org.neo4j.jdbc.Driver
      Bolt : org.neo4j.jdbc.bolt.BoltDriver
      HTTP : org.neo4j.jdbc.http.HttpDriver
    • URL format:
      Bolt : jdbc:neo4j:bolt://<serverName>/<databaseName>
      HTTP : jdbc:neo4j:https://<serverName>/<databaseName>
As part of the connection string, a series of connection arguments can be passed into the driver that will affect its behavior.

Code Walkthrough with Bolt


//
// Create a new instance of the JDBC Driver for Neo4j and connect to the URL:
//
String url = "jdbc:neo4j:bolt://localhost";
try (Connection con = DriverManager.getConnection(url, "neo4j", "neo4j")) {
  //
  // Create a PreparedStatement and submit a Cypher query:
  //
  String sql = "MATCH (u:User)-[:FRIEND]-(f:User) " +
               "WHERE u.name = {1} " +
               "RETURN f.name as name, f.age as age";
 
  try (PreparedStatement stmt = con.prepareStatement(query)) {
    stmt.setString(1,"John");
    //
    // Iterate and print out the result set
    //
    try (ResultSet rs = stmt.execute()) {
      while (rs.next()) {  
        System.out.println(
          "Friend: " + rs.getString("name") + " is " + rs.getInt("age"));
      }
    }
  }
}

Please notice that Connection, Statement/PreparedStatement and ResultSet are all AutoCloseable and this can better protect from any eventual resource leak.

Just change your URL to jdbc:neo4j:https://localhost in order to make use of the HTTP protocol instead of the Bolt one.

Next Steps


We’re currently testing the Neo4j JDBC Driver with the newly released Neo4j 3.2.0 and adding new examples.

Also, we’d love to take advantage of the bolt+routing protocol in order to make read-only queries to access a Causal Cluster’s Read Replica nodes. The general idea would be to access these instances as soon as the java.sql.Connection is set to read only:

String url = "jdbc:neo4j:bolt://localhost";
try (Connection con = DriverManager.getConnection(url, "neo4j", "neo4j")) {
  //
  // Switching connection to read only will make all queries access
  // to Read Replica nodes
  //
  con.setReadOnly(true);
 
  String sql = "MATCH (u:User)-[:FRIEND]-(f:User) " +
               "WHERE u.name = {1} " +
               "RETURN f.name as name, f.age as age";
 
  try (PreparedStatement stmt = con.prepareStatement(query)) {
    // ...
  }
}

We Need Your Feedback


Please provide feedback and report bugs as GitHub issues or join the neo4j-users Discord and ask on the #neo4j-jdbc channel. You might also ask on Stack Overflow, please tag your question there with neo4j and jdbc.


Add Neo4j to your existing Oracle RDBMS infrastructure: Download this white paper How Neo4j Co-exists with Oracle RDBMS and harness the power of a graph database to uncover rich data connections.

Read the White Paper



Pictures from GraphConnect Europe


LARUS BA presenting at GraphConnect

Omar Rampado, CTO at LARUS presenting Doc2Graph

Working on the JDBC driver at GraphConnect Europe

Lorenzo & Konstantin in the Developer Zone at GraphConnect Europe while working on the Neo4j JDBC Driver

Learn about the new Neo4j JDBC Bolt driver now available for Neo4j 3.0 & 3.1 (with 3.2 coming soon!)


Michael Hunger presenting on the JDBC driver


LARUS team and Neo4j developer relations


Working on the JDBC driver at GraphConnect Europe with the LARUS team

LARUS Team working with Michael, Konstantin and Praveena at SkillMatters