问题描述
我试图在Neo4j社区中可视化Java嵌入式图。
/*
* Licensed to Neo4j under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional @R_543_4045@ion regarding copyright
* ownership. Neo4j licenses this file to you under
* the Apache License,Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,* software distributed under the License is distributed on an
* "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND,either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.io.File;
import java.io.IOException;
import org.neo4j.dbms.api.DatabaseManagementService;
import org.neo4j.dbms.api.DatabaseManagementServiceBuilder;
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;
public class Embedded3 {
private static final File databaseDirectory = new File(
"/home/nicolas/neo4j-community-4.1.1/data/databases/new.db");
public String greeting;
// tag::vars[]
GraphDatabaseService graphDb;
Node firstNode;
Node secondNode;
Relationship relationship;
private DatabaseManagementService managementService;
// end::vars[]
// tag::createReltype[]
private enum RelTypes implements RelationshipType {
KNowS
}
// end::createReltype[]
public static void main(final String[] args) throws IOException {
Embedded3 hello = new Embedded3();
hello.createDb();
// hello.removeData();
hello.shutDown();
}
void createDb() throws IOException {
// tag::startDb[]
managementService = new DatabaseManagementServiceBuilder(databaseDirectory).build();
graphDb = managementService.database("neo4j");
registerShutdownHook(managementService);
try (Transaction tx = graphDb.beginTx()) {
// Database operations go here
firstNode = tx.createNode();
firstNode.setProperty("message","Hello,");
secondNode = tx.createNode();
secondNode.setProperty("message","World!");
relationship = firstNode.createRelationshipTo(secondNode,RelTypes.KNowS);
relationship.setProperty("message","brave Neo4j ");
// end::addData[]
greeting = ((String) firstNode.getProperty("message")) + ((String) relationship.getProperty("message"))
+ ((String) secondNode.getProperty("message"));
// tag::transaction[]
tx.commit();
}
}
void shutDown() {
System.out.println();
System.out.println("Shutting down database ...");
// tag::shutdownServer[]
managementService.shutdown();
// end::shutdownServer[]
}
// tag::shutdownHook[]
private static void registerShutdownHook(final DatabaseManagementService managementService) {
// Registers a shutdown hook for the Neo4j instance so that it
// shuts down nicely when the VM exits (even if you "Ctrl-C" the
// running application).
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
managementService.shutdown();
}
});
}
// end::shutdownHook[]
}
之后,我在neo4j.conf中将dbms.default_database
的值更改为dbms.default_database=new.db
。
启动neo4j时,数据库实现良好: Database parameters in Neo4j community
但是当我运行简单的查询MATCH (n) return n
时,数据库中没有要显示的记录。
然后,我从neo4j浏览器成功创建了一些节点。但是用我的Java代码无法读取它们,数据库看起来空了。
我的代码中肯定有一个错误,但是我现在真的被卡住了。 感谢您的帮助。
尼古拉斯。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)