userimage

Establish connection with Neo4j 3.X using JDBC driver

Currently I am using the 2.x version of Neo4j and recently came to know about the new release of 3.x and I want to use this on my current application but facing issue with connection establishment. Please let me know the proper way to make a JDBC connection between Java application and Neo4j. Thanks for the suggestion.
userimage

To connect with neo4j 3.x using new java driver, follow these steps:

 

Add the new java driver in pom.xml file

 

<!-- http://mvnrepository.com/artifact/org.neo4j.driver/neo4j-java-driver -->

<dependency>

    <groupId>org.neo4j.driver</groupId>

    <artifactId>neo4j-java-driver</artifactId>

    <version>1.0.2</version>

</dependency>

 

If require please add the repository as below:

 

<repository>

                <id>neo4j-public</id>

                <url>https://m2.neo4j.org/content/repositories/releases</url>

                <releases>

                                <enabled>true</enabled>

                                <checksumPolicy>warn</checksumPolicy>

                </releases>

</repository>

 

Once dependency jar downloaded try the below code to connect with neo4 3.x using new java driver.

package com.neo4j.connection;

import java.sql.SQLException;
import java.util.Objects;

 

import org.neo4j.driver.v1.AuthTokens;
import org.neo4j.driver.v1.Driver;
import org.neo4j.driver.v1.GraphDatabase;

 
/**
 * Will be static pool to gain neo4j database connection.
 *
 * @author Cristopher 09 June 2016
 *
 */
public class Neo4jConnections {
                private static Driver driver = null;
                static {
                                connection();
                }

                /**
                 *
                 * @return
                 * @throws SQLException
                 */
                public static Driver getConnection() {
                                if (Objects.isNull(driver)) {
                                                connection();
                                }
                                return driver;
                }

                /**
                 *
                 */
                private static void connection() {
                                driver = GraphDatabase.driver("bolt://localhost",
                                                                AuthTokens.basic("userid","password"));
                }
}
Answer is