gpt4 book ai didi

java - 在 neo4j [JAVA] 中发送查询

转载 作者:行者123 更新时间:2023-12-01 12:32:12 26 4
gpt4 key购买 nike

我是 Neo4j 和图形数据库的新手,我必须发送查询才能获取一些值。

我有foodcategory节点,两者之间的关系类型由另一个节点categorized_as指定。

我需要获取的是food_name及其category_name对。

感谢您提前提供的帮助。

最佳答案

Here's the documentation on how to run cypher queries from java 。根据您的示例进行调整,它看起来像这样:

// Create a new graph DB at path DB_PATH
GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase( DB_PATH );

// Create a new execution engine for running queries.
ExecutionEngine engine = new ExecutionEngine( db );

ExecutionResult result;

// Queries need to be run inside of transactions...
try ( Transaction ignored = db.beginTx() )
{
String query = "MATCH (f:food)-[:categorized_as]->(c:category) RETURN f.food_name as foodName, c.category_name as categoryName";

// Run that query we just defined.
result = engine.execute(query);

// Pull out the "foodNames" column from the result indicated by the query.
Iterator<String> foodNames = result.columnAs( "foodName" );
// Iterate through foodNames...
}

关于java - 在 neo4j [JAVA] 中发送查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25849935/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com