繁体   English   中英

在Java中创建Neo4j关系

[英]Creating Neo4j Relationships in java

我正在基于no在java类中创建唯一的neo4j关系。 数据库中的列值。 “ Interface_Name”列的值将分配给每个关系。我的代码:

while (rs.next()){
    String rel = rs.getString("Interface_Name");
    GraphDatabaseService graphDb = new EmbeddedGraphDatabase("D://My Graph");
    Transaction tx = graphDb.beginTx();     
    try {       
        RelationshipType rel = DynamicRelationshipType.withName(rel); **//Gives error since rel is string** 
        .....
        tx.success();
    }
}

我如何根据DB中的列值创建关系类型?while循环关系类型应根据DB值创建。

不创建节点就无法创建关系。 您将需要一个开始节点和一个结束节点。 另外,不要为遇到的每个列创建一个新的GraphDatabaseService 您的代码可能是这样的:

GraphDatabaseService graphDb = new EmbeddedGraphDatabase("D://My Graph");
while (rs.next()){
    String rel = rs.getString("Interface_Name");
    try (Transaction tx = graphDb.beginTx()) {
         RelationshipType relType = DynamicRelationshipType.withName(rel);
         graphDb.createNode().createRelationshipTo(graphDb.createNode(), relType);
         tx.success();
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM