3

我有一个用于连接 neo4j 的 java 程序。想要将参数传递给密码查询,该参数是用户给定的变量值。

    void connect() {

    graphDataService = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
    Transaction transaction = graphDataService.beginTx();

    String name = "";

    Scanner sc_name = new Scanner(System.in);
    System.out.println("enter name : ");
    name=sc_name.next();

    try {
        ExecutionEngine engine = new ExecutionEngine(graphDataService);
        ExecutionResult result = engine.execute("START n = node(*) where n.nodename = ? return n");
        System.out.println(result.dumpToString());
        transaction.success();
    }

    finally {
        transaction.finish();
    }
}

我应该如何连接将替换的变量名中的值并获取结果。任何想法?

4

1 回答 1

5

您可以执行以下操作:

import org.neo4j.helpers.collection.MapUtil;
...
ExecutionResult result = engine.execute("START n=node(*) WHERE n.nodename={name}, return n", MapUtil.map("name", "value");
于 2013-08-29T11:39:52.510 回答