0
votes

I have already loaded 50k nodes and established relationships between them through talend. I wrote java code to connect to neo4j and try to execute cypher query. It is connecting to neo4j but showing wrong results. My java code is:

package com.Neo4J;

import org.neo4j.cypher.javacompat.ExecutionEngine;
import org.neo4j.cypher.javacompat.ExecutionResult;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;

public class CaseNeo4J {

private static final String Neo4J_DBPath="/neo4j-community-1.9.2/data/graph.db";
GraphDatabaseService gdb;

public void connect(){

    gdb = new GraphDatabaseFactory().newEmbeddedDatabase(Neo4J_DBPath);
    Transaction transaction = gdb.beginTx();
    ExecutionEngine engine = new ExecutionEngine(gdb);
    ExecutionResult result = engine.execute( "start n=node(*) return n");
    System.out.println(result.dumpToString());
}

public static void main(String[] args) {

    CaseNeo4J neoobj = new CaseNeo4J();
    neoobj.connect();

}
}

outputs as :
+-----------+
| n         |
+-----------+
| Node[0]{} |
+-----------+
1 row

Actully it should show 50000 nodes but it is showing ony 1... Any idea?

1
It seems to me, the embedded database is actually empty. Probably you did not really connect to the database but create a new one. Is the directory /neo4j-community-1.9.2 the downloaded server package from the Neo4j website? Because then, the data should actually be located in /neo4j-community-1.9.2/data/graph.db. If you look now, there will be the directory /neo4j-community-1.9.2/graph.db because your code created it. But it's seemingly empty. - khituras
Yes.. I have downloaded it from neo4j site itself. Also it is not empty because I have localhost:7474 running which shows 50000 nodes and 100000 relationships. Also I am able to run cypher query on web UI which gives me correct results. - Saurabh Deshpande
Yes, but the path is wrong, isn't it? As long as you are pointing your java code to /neo4j-community-1.9.2you won't see the data you inserted into the sever. - khituras
I tried giving path upto graph.db I am getting the same result - Saurabh Deshpande
Sorry if I'm annoying, but what exact path did you give? only graph.db? The full path should be - as I wrote in my first comment /neo4j-community-1.9.2/data/graph.db. If there is still nothing then, I don't know. Perhaps make sure the server is down when using the Java class. - khituras

1 Answers

0
votes

Sorry if my inswer is too obvious but have you tried with: MATCH(n) RETURN n as the query?