Hot questions for Using Neo4j in csv

Question:

How can I use this cypher query using APOC in Java program?

CALL apoc.export.csv.query("match (m:Movie) where m.name='Matrix'
RETURN m.name","results.csv",{})

If any one can refer/suggest to sample JAVA code, it would be great. A few lines or one line code, I shall a thankful.

Following is my Sample code which is giving error at line:

StatementResult result = session.run("CALL apoc.export.csv.query("match (m:Movie) where m.name='Matrix' return m.name","results.csv",{})");

/////

public class bolt {

    public static void main(String[] args) {

        Driver driver = GraphDatabase.driver("bolt://127.0.0.1:7687", AuthTokens.basic("neo4j", "neo4j"));
        Session session = driver.session();
        StatementResult result = session.run("CALL apoc.export.csv.query("match (m:Movie) where m.name='Matrix' return m.name","results.csv",{})");

        session.close();
        driver.close();
    }

}

Answer:

Just escape the quotation characters inside the string.

StatementResult result = session.run(
    "CALL apoc.export.csv.query(\"match (m:Movie) where m.name='Matrix' return m.name\",\"results.csv\",{})"
);

Question:

I am uploading a 100MB csv file to neo4j containing transactional data. I am getting a java error that I cannot seem to trace to a setting or something that I can change.

neo4j-sh (?)$ CREATE CONSTRAINT ON (a:Account) ASSERT a.id IS UNIQUE;
+-------------------+
| No data returned. |
+-------------------+
Constraints added: 1
48 ms
neo4j-sh (?)$ USING PERIODIC COMMIT
> LOAD CSV FROM
>   "file:/somepath/findata.csv"
>   AS line
>   FIELDTERMINATOR ','
> MERGE (a1:Account { id: toString(line[3]) })
> MERGE (a2:Account { id: toString(line[4]) })
> CREATE (a1)-[:LINK { value: toFloat(line[0]), date: line[5] } ]->(a2);
java.rmi.UnmarshalException: Error unmarshaling return header; nested exception is:
    java.io.EOFException
    at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:228)
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:161)
    at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:194)
    at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:148)
    at com.sun.proxy.$Proxy1.interpretLine(Unknown Source)
    at org.neo4j.shell.impl.AbstractClient.evaluate(AbstractClient.java:110)
    at org.neo4j.shell.impl.AbstractClient.evaluate(AbstractClient.java:94)
    at org.neo4j.shell.impl.AbstractClient.grabPrompt(AbstractClient.java:74)
    at org.neo4j.shell.StartClient.grabPromptOrJustExecuteCommand(StartClient.java:357)
    at org.neo4j.shell.StartClient.startRemote(StartClient.java:303)
    at org.neo4j.shell.StartClient.start(StartClient.java:175)
    at org.neo4j.shell.StartClient.main(StartClient.java:120)
Caused by: java.io.EOFException
    at java.io.DataInputStream.readByte(DataInputStream.java:267)
    at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:214)
    ... 11 more

I've tried the command twice and it gives me the same error. Sofar google has not helped me to figure out what I can do to circumvent this error. What is happening in neo4j and how could I solve this?


Answer:

Maybe this isn't the problem, but your path to your CSV file may be malformed. This would explain the java.rmi.UnmarshalException. The path should be 'file://', where would be something like '/home/cantdutchthis/findata.csv' on a linux system. On a linux or Mac machine, this means that there will be 3 '/'s - 'file:///home/cantdutchthis/findata.csv'.

Grace and peace,

Jim