0

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();
    }

}
Bruno Peres
  • 15,845
  • 5
  • 53
  • 89
Faaiz
  • 635
  • 8
  • 18

1 Answers1

1

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\",{})"
);
Gabor Szarnyas
  • 4,410
  • 3
  • 18
  • 42