【发布时间】:2014-07-26 01:41:40
【问题描述】:
我是 neo4j 的新手,我正在努力学习,
我有以下java代码在neo4j中创建节点,然后我在java中读取了创建节点的属性名称,我的代码如下:
String DB_PATH = "C:/hamed";
public static void main( String[] args )
{
JavaQuery javaQuery = new JavaQuery();
javaQuery.run();
}
void run()
{
// START SNIPPET: addData
GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase( DB_PATH );
db.beginTx();
try ( Transaction tx = db.beginTx(); )
{
Node myNode = db.createNode();
myNode.addLabel( DynamicLabel.label( "11" ) );
myNode.setProperty( "name", "qq" );
tx.success();
}
// END SNIPPET: addData
// START SNIPPET: execute
ExecutionEngine engine = new ExecutionEngine( db );
ExecutionResult result;
try ( Transaction ignored = db.beginTx() )
{
result = engine.execute( "match (n) return n, n.name" );
// END SNIPPET: execute
// START SNIPPET: items
Iterator<Node> n_column = result.columnAs( "n" );
for ( Node node : IteratorUtil.asIterable( n_column ) )
{
// note: we're grabbing the name property from the node,
// not from the n.name in this case.
nodeResult = node + ": " + node.getProperty( "name" );
System.out.println("ss : "+nodeResult);
}
// END SNIPPET: items
db.shutdown();
}
system.out... 打印 ss : Node1: qq 这很好,
现在当我按如下方式运行 neo4j 时:
然后我去这个链接:
http://localhost:7474/webadmin/
然后当我编写查询来检查节点时,什么都没有返回:
但我希望看到一个具有 qq 名称属性的节点
谁能帮助我?我做错了什么?
更新:
我明白该代码只会从 db 中删除所有节点。例如,我创建了一个节点并使用 neo4j 控制台检查它: match (n) return n 并且节点返回但运行代码后没有返回任何内容,这很奇怪!!!!!!!!!!
【问题讨论】:
标签: neo4j