import org.neo4j.driver.v1.AuthTokens;
import org.neo4j.driver.v1.Driver;
import org.neo4j.driver.v1.GraphDatabase;
import org.neo4j.driver.v1.Session;
public class ForStackoverflowQuestion {
public static void main(String[] args) {
Driver driver = GraphDatabase.driver(
"bolt://localhost:7687", AuthTokens.basic("neo4j", "12345"));
Session session = driver.session();
String Node1 = "Software_Engineer";
String Node2 = "Programming_Language";
String relationBetweenNode1andNode2 = "LEARNS";
String PersonNameAttribute = "name";
String PersonNameValue = "Jaykant";
String ProgrammingLanguageAttribute = "version";
String ProgrammingLanguageValue = "Neo4j";
String t = "MERGE(n1:"+Node1+"{"+PersonNameAttribute+":\""+PersonNameValue+"\"})"+"-[:"+relationBetweenNode1andNode2+"]->(n2:" + Node2 +" {"+ProgrammingLanguageAttribute+":'"+ProgrammingLanguageValue+"'})";
System.out.println(t);
session.run(t);
session.close();
driver.close();
}
}
据我所知,上面的代码没有使用参数化Cypher查询;所以它不会在neo4j中生成任何查询计划。
为了使用查询计划并从中受益,我需要使用参数化查询。
如何将这个简单的Cypher查询转换为参数化查询以使用存储在变量(Java)中的值?
如果不是Node1,Node2和relationBetweenNode1andNode2作为参数,则至少可以将以下值作为参数传递。
PersonNameAttribute = "name";
PersonNameValue = "Jaykant";
ProgrammingLanguageAttribute = "version";
ProgrammingLanguageValue = "Neo4j";
Create (n:Person{name:{name}})Return n
我想在查询之上运行neo4j桌面浏览器。如何传递参数值?
"params":{"name":"Will Smith"}
节点和关系类型(Node1,Node2和relationBetweenNode1andNode2)不能作为参数传递,但您可以将以下参数作为参数传递:
PersonNameAttribute = "name";
PersonNameValue = "Jaykant";
ProgrammingLanguageAttribute = "version";
ProgrammingLanguageValue = "Neo4j";
以上是here回答。
您可以在Neo4j浏览器中传递参数:
查询:
Create (n:Person{name:{name}})Return n
参数:
:params {"name":"Will Smith"}