gpt4 book ai didi

java - 执行引擎不打印结果

转载 作者:行者123 更新时间:2023-11-29 05:24:04 27 4
gpt4 key购买 nike

我有一个简单的查询方法,它运行如下所述的密码查询。如果我在 Web 控制台中运行完全相同的查询(是的,相同的数据库实例,正确的路径),我会在控制台中得到一个 non-empty iterator。难道我不应该 1) 不收到该消息和 2) 获得我在数据库中看到的结果吗?

这个类还有其他方法可以将数据添加到数据库中,并且该功能运行良好。该查询方法无效...

类:

import org.neo4j.cypher.javacompat.ExecutionEngine;
import org.neo4j.cypher.javacompat.ExecutionResult;
import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
import org.neo4j.helpers.collection.IteratorUtil;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.sql.*;

public class NeoProcessor {

//private GraphDatabaseService handle;
private static final String DB_PATH = "/usr/local/Cellar/neo4j/2.0.1/libexec/data/new_graph.db";
static GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase( DB_PATH );


public NeoProcessor()
{
}


public void myQuery(String cypherText)
{
//System.out.println("executing the above query");
cypherText = "MATCH (n:Phone{id:'you'}) MATCH n-[r:calling]->m WHERE n<>m RETURN n, r, m";

ExecutionEngine engine = new ExecutionEngine( this.graphDb );

ExecutionResult result;
try ( Transaction ignored = graphDb.beginTx() )
{
result = engine.execute( cypherText + ";");
System.out.println(result);

ignored.success();
}

}
}

下图展示了查询如何从数据库返回结果:

enter image description here

最佳答案

result = engine.execute(cypherText + ";");
System.out.println(result.dumpToString());

Specified by: http://api.neo4j.org/2.0.3/org/neo4j/cypher/javacompat/ExecutionResult.html#dumpToString()

关于java - 执行引擎不打印结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23404203/

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