2

I am attempting to use Neo4j's JDBC Driver with an Embedded Neo4j. I've copied the jars, configured the build path, wrote the code to create the GraphDatabaseService as the limited instructions dictate. I am lost, however, on how to get the JDBC to point to the embedded (and running, hopefully) server.

The URL I specify for the JDBC is "jdbc:neo4j:simulationDb?debug=true". How and where do I set this for the embedded server?

2
  • what do you mean with embedded server? Commented Nov 19, 2014 at 0:35
  • you can embed neo4j into your project: neo4j.com/docs/stable/… Commented Nov 19, 2014 at 0:46

2 Answers 2

3

If you're connecting to the embedded database, then your JDBC url needs to look like:

jdbc:neo4j:file:/home/user/neo/graph.db where /home/user/neo/graph.db is the path to your Neo4j database.

Then get a java.sql.Connection to it using

Connection con = DriverManager.getConnection("jdbc:neo4j:file:/home/user/neo/graph.db");

There isn't any such thing as the Embedded Server- it's either embedded in your application(as per the link you supplied), or server mode where Neo4j runs as a standalone server. If you're running in server mode, your JDBC URL looks like jdbc:neo4j://localhost:7474/ (if your Neo4j server runs on localhost:7474) and you obtain a Connection the same way.

There's some sample code using the JDBC driver here https://github.com/luanne/flavorwocky-jdbc-migrate/blob/master/src/com/flavorwocky/migrate/MigrateDb.java

Sign up to request clarification or add additional context in comments.

4 Comments

Unfortunately, we cannot run the neo4j server in standalone mode and need to configure JDBC to use the embedded server, as per these instructions: Existing Graph Database Instance Connect with URLs on the form jdbc:neo4j:instance:name, e.g. jdbc:neo4j:mem:mydb and put the GraphDatabaseService object instance under the same name into the properties provided to the driver I am lost at the "putting the object under the same name".
Not sure why you need to use an existing GraphDatabaseService instance. Connecting using the form jdbc:neo4j:file:/home/user/neo/graph.db where /home/user/neo/graph.db is the path to your Neo4j database is more than sufficient. However if you still want to use an existing instance of a GraphDatabaseService, then I believe you will have to pass that instance via the jdbc properties, with a key equal to <some_name> where <some_name> is part of the JDBC url jdbc:neo4j:file:<some_name>
Hi Luanne, Thanks for your help on this. We do have to use an existing instance since we have to deliver neo4j within the stand-alone application. According to the docs, I pass the JDBC ""jdbc:neo4j:simulationDb", where simulationDb is the name of the variable. I'm assuming this is what's meant by 'instance name' in the docs - how do I give the GraphDatabaseService the name of 'simulationDb'? Or do I have it completely wrong here...
@bcwebb88 does the driver really support connecting over the file protocol? We are trying to implement just this, but seemingly cant get it to work. We could however get it to work using the BOLT protocol and some extra properties on the db and some extra maven dependencies, as described here: stackoverflow.com/questions/52132826/…
1

Actually...I just figured it out. For posterity's sake, I'll post the code snippet here.

simulationDb = new GraphDatabaseFactory() 
.newEmbeddedDatabaseBuilder(DB_PATH)
.loadPropertiesFromFile(CONFIG_PATH) 
.newGraphDatabase(); 

registerShutdownHook(simulationDb); 

Class.forName(JDBC_DRIVER); 

Properties props = new Properties(); 
props.put("simulationDb", simulationDb); 

db = DriverManager.getConnection(URL, props);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.