Problem connecting to remote Neo4J using Java

305 views
Skip to first unread message

Mohana Krishna, IIT Bombay, India

unread,
Sep 24, 2014, 9:46:56 PM9/24/14
to ne...@googlegroups.com
I am trying to connect to remote neo4j server and perform some cypher queries on it. I am using the reference example: https://github.com/neo4j/neo4j/blob/2.1.4/community/cypher/docs/cypher-docs/src/test/java/org/neo4j/cypher/example/JavaQuery.java
But I do not get how to configure my code so as to access remote neo4j server. 

I am also not clear with what exactly "DB_PATH" in above program refers to. I have given my path as "/var/lib/neo4j/data/graph.db" for local neo4j server. But it says permission denied even though graph.db folder can be accessed by all users as can be seen in permission settings.

So, I need help regarding two things:

1) What exactly is "DB_PATH"? Am I wrong in my understanding of path? If not, why I am unable to connect to my local neo4j server and perform a simple cypher query on it? (Why permission denied?)

2) How to access remote neo4j server from java code?

Somebody please help. I am novice in using neo4j with Java and this is my first project. Thanks in advance.

Mohana Krishna, IIT Bombay, India

unread,
Sep 24, 2014, 9:54:08 PM9/24/14
to ne...@googlegroups.com
I am using Neo4J 2.1.4

Mohana Krishna, IIT Bombay, India

unread,
Sep 24, 2014, 10:00:14 PM9/24/14
to ne...@googlegroups.com
Precisely I am getting this error when using local server from Java:

Exception in thread "main" java.lang.RuntimeException: java.nio.file.AccessDeniedException: /var/lib/neo4j/data/graph.db/neostore.schemastore.db.id
at neo4j.graphminer.clearDbPath(graphminer.java:100)
at neo4j.graphminer.run(graphminer.java:36)
at neo4j.graphminer.main(graphminer.java:31)
Caused by: java.nio.file.AccessDeniedException: /var/lib/neo4j/data/graph.db/neostore.schemastore.db.id
at sun.nio.fs.UnixException.translateToIOException(UnixException.java:84)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
at sun.nio.fs.UnixFileSystemProvider.implDelete(UnixFileSystemProvider.java:244)
at sun.nio.fs.AbstractFileSystemProvider.delete(AbstractFileSystemProvider.java:103)
at java.nio.file.Files.delete(Files.java:1079)
at org.neo4j.kernel.impl.util.FileUtils.deleteFileWithRetries(FileUtils.java:453)
at org.neo4j.kernel.impl.util.FileUtils.access$000(FileUtils.java:46)
at org.neo4j.kernel.impl.util.FileUtils$1.visitFile(FileUtils.java:61)
at org.neo4j.kernel.impl.util.FileUtils$1.visitFile(FileUtils.java:57)
at java.nio.file.FileTreeWalker.walk(FileTreeWalker.java:135)
at java.nio.file.FileTreeWalker.walk(FileTreeWalker.java:199)
at java.nio.file.FileTreeWalker.walk(FileTreeWalker.java:69)
at java.nio.file.Files.walkFileTree(Files.java:2602)
at java.nio.file.Files.walkFileTree(Files.java:2635)
at org.neo4j.kernel.impl.util.FileUtils.deleteRecursively(FileUtils.java:56)
at neo4j.graphminer.clearDbPath(graphminer.java:96)
... 2 more



On Thursday, 25 September 2014 07:16:56 UTC+5:30, Mohana Krishna, IIT Bombay, India wrote:

Michael Hunger

unread,
Sep 25, 2014, 1:11:04 AM9/25/14
to ne...@googlegroups.com
If you use your java program accessing the on disk datastore the server must not be running 

Check the filesystem permission for the db-files so that your user is able to read and write

Von meinem iPhone gesendet
--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Craig Taverner

unread,
Sep 25, 2014, 7:32:41 AM9/25/14
to ne...@googlegroups.com
Mohana,

You are looking at code for the embedded API (ie. a database running inside the same java process), but you said you want to access a remote database. This is a completely different thing. Do not use that code at all. Rather look at the docs at http://docs.neo4j.org/chunked/stable/server-java-rest-client-example.html. There are code examples for you there too.

Regards, Craig

--

Mohana Krishna, IIT Bombay, India

unread,
Sep 25, 2014, 9:08:02 AM9/25/14
to ne...@googlegroups.com
I want to run CYPHER queries on remote neo4j server using java much like the way we do for SQL using java and use results for computations. I need to connect to remote neo4j, perform cypher queries, get results much like 'result set' in sql-java. Do that need to be done through REST? Am I missing something? Please reply.

Mohana Krishna, IIT Bombay, India

unread,
Sep 25, 2014, 5:35:37 PM9/25/14
to ne...@googlegroups.com
Craig, Please reply.


On Thursday, 25 September 2014 07:16:56 UTC+5:30, Mohana Krishna, IIT Bombay, India wrote:

Craig Taverner

unread,
Sep 25, 2014, 6:58:06 PM9/25/14
to ne...@googlegroups.com
All remote access to Neo4j should be done through REST. The documents I mentioned before show this. Look at http://docs.neo4j.org/chunked/stable/server-java-rest-client-example.html. There are code examples for you there too.

However, there are easier libraries that can make working with Neo4j much easier than the lower level REST API. The neo4j.org website has a lot of pointers to various options. Take a look at:

--

Mark Findlater

unread,
Sep 26, 2014, 4:47:25 AM9/26/14
to ne...@googlegroups.com
Mohana, have you looked at the Neo4J JDBC driver? https://github.com/neo4j-contrib/neo4j-jdbc#neo4j-jdbc-driver I confess that I have not used it, but a quick look around and seeing that it is being actively maintained suggests that it is a great option. Under the hood it will use the REST endpoint but maybe you will feel more comfortable with the syntax.

M

Mohana Krishna, IIT Bombay, India

unread,
Sep 28, 2014, 10:45:45 AM9/28/14
to ne...@googlegroups.com
Thanks Mark for your pointer. I am looking into it. I have run a sample program using this on Movie database with the query "MATCH (n:Person) return count(n) as count;".

I am getting the following output:

Starting the Apache HTTP client
Connecting to URL http://10.129.13.25:7474/
Executing query: MATCH (n:Person) return count(n) as count;
 with params {}
Starting the Apache HTTP client
Unexpected token END_ARRAY
133
errors-next-token = FIELD_NAME
null

'133' is the expected answer. But why is it printing unnecessary lines especially "Unexpected token END_ARRAY", "errors-next-token = FIELD_NAME","null" ? How can I get rid of them and have the end result only?

Perhaps Michael could help(I am executing this using read me put up by Michael). Michael, Please reply. Thanks.


On Thursday, 25 September 2014 07:16:56 UTC+5:30, Mohana Krishna, IIT Bombay, India wrote:

Michael Hunger

unread,
Sep 28, 2014, 11:39:39 AM9/28/14
to ne...@googlegroups.com
Should be resolved in the latest 2.1.4 version

Von meinem iPhone gesendet
--

Mohana Krishna, IIT Bombay, India

unread,
Sep 28, 2014, 9:02:21 PM9/28/14
to ne...@googlegroups.com
Michael,

The current version in the link: https://github.com/neo4j-contrib/neo4j-jdbc is 2.0.1. Is this the latest version? If not where can I get the latest JDBC jar? 

When can we expect version - 2.1.4 ?

On Thursday, 25 September 2014 07:16:56 UTC+5:30, Mohana Krishna, IIT Bombay, India wrote:

Michael Hunger

unread,
Sep 28, 2014, 9:15:30 PM9/28/14
to ne...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages