我有一个用于连接neo4j的java程序。希望传递参数,该参数是用户给cypher查询赋予的变量值。
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();
}
}
如何连接将替换?的变量名称中的值并获取结果。有什么想法吗?
答案 0 :(得分:5)
您可以执行以下操作:
import org.neo4j.helpers.collection.MapUtil;
...
ExecutionResult result = engine.execute("START n=node(*) WHERE n.nodename={name}, return n", MapUtil.map("name", "value");