簡體   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