我创建了一个使用neo4j的小型java应用程序。应用程序运行成功,当我打开neo4j管理控制台时,它没有显示数据。以下是我遵循的步骤。
MainApp.java
GraphDatabaseFactory dbFactory = new GraphDatabaseFactory();
GraphDatabaseService db = dbFactory.newEmbeddedDatabase(new File("<location>/lang.db"));
Transaction tx = db.beginTx();
Node javaNode = db.createNode(Tutorials.JAVA);
javaNode.setProperty("TutorialID", "JAVA001");
javaNode.setProperty("Title", "Learn Java");
javaNode.setProperty("NoOfChapters", "25");
javaNode.setProperty("Status", "Completed");
Node scalaNode = db.createNode(Tutorials.SCALA);
scalaNode.setProperty("TutorialID", "SCALA001");
scalaNode.setProperty("Title", "Learn Scala");
scalaNode.setProperty("NoOfChapters", "20");
scalaNode.setProperty("Status", "Completed");
Relationship relationship = javaNode.createRelationshipTo
(scalaNode, TutorialRelationships.JVM_LANGIAGES);
relationship.setProperty("Id", "1234");
relationship.setProperty("OOPS", "YES");
relationship.setProperty("FP", "YES");
tx.success();
System.out.println("Done successfully");
db.shutdown();
System.out.println("DB Shut down");
public enum Tutorials implements Label {
JAVA,SCALA,SQL,NEO4J;
}
public enum TutorialRelationships implements RelationshipType{
JVM_LANGIAGES,NON_JVM_LANGIAGES;
}
当我运行它时,它在lang.db文件夹中创建文件。 (几个文件)
然后我启动Neo4j Community Edition转轮并将路径设置为lang.db.它成功地开始了。 当我首先导航到http://localhost:7474/时,它要求登录(neo4j / neo4j)并更改密码。
当我查看数据库信息时,我可以看到属性键但不能看到关系类型。甚至DB位置也已正确配置。
但是当我尝试运行一些命令MATCH (n) RETURN n LIMIT 100
时,它说没有行。我在这里做错了吗?
答案 0 :(得分:0)
想通。我们需要关闭事务以提交更改。
tx.close();