cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Connecting to neo4j using java

Hi All,

Im trying to connect to neo4j using java using neo4j driver. The connectivity is successful when i try it from eclipse, but when i deploy the same class it its throwing error "No suitable driver found for jdbc:neo4j:bolt://localhost:port". The same jar is also present in the web application.

code Snippet:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

Connection conn = DriverManager.getConnection("jdbc:neo4j:bolt://localhost:port") ;
System.out.println("Initiating the method");
long startTime = System.currentTimeMillis();
PreparedStatement stmt = conn.prepareStatement("MATCH (Actors:Actors) RETURN Actors.Name");
ResultSet rset = stmt.executeQuery();
long endTime = System.currentTimeMillis();
System.out.println("That took " + (endTime - startTime) + " milliseconds");

Requesting for inputs on the issue.

5 REPLIES 5

Make sure you have included the neo4j-jdbc-driver in your dependencies.

My Application is not a maven application. Its a java standalone application. I have included ```
neo4j-jdbc-driver:3.3.1 as thirdparty jar. Still its not working.

But if we use

Driver driver = GraphDatabase.driver(
URL, AuthTokens.basic( "neo4j", "password" ) );
Session session = driver.session();

its working. But we are seeing some performance issues with this. . The throughput is very low if we use GraphDatabse.driver since we are creating session explicitly and then querying. So wanted to use the other option to retrieve the data and check if its quick. My other application is working with oracle as the backend database. We are making the api call to neo4j for retrieving data for one of the functionalities.

Have you ever try using this parameters?

Connection con = DriverManager.getConnection("jdbc:neo4j:bolt://localhost", 'user', password);

Because you only provided the URL and Port

Connection conn = DriverManager.getConnection ("jdbc: neo4j: bolt: // localhost: port")

@leonardo.bouchan I will try passing these parameters as well and get back.

This started working now after i added the following piece of code.

Class.forName("org.neo4j.jdbc.Driver").newInstance();