0
我想爲Neo4j使用'Hello World'。問題是,當我啓動服務器並檢查neo4j的瀏覽器(localhost:7474)時,我看不到任何圖形顯示我的節點。Neo4j - 瀏覽器可視化錯誤
import java.io.File;
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;
public class MyFirstMain
{
private static final String DB_PATH = "/neo4j/data/graph.db";
public String greeting;
// START SNIPPET: vars
GraphDatabaseService graphDb;
Node firstNode;
Node secondNode;
Relationship relationship;
// END SNIPPET: vars
// START SNIPPET: createReltype
private static enum RelTypes implements RelationshipType
{
KNOWS
}
// END SNIPPET: createReltype
public static void main(final String[] args)
{
MyFirstMain hello = new MyFirstMain();
hello.createDb();
// hello.removeData();
// hello.shutDown();
}
void createDb()
{
// START SNIPPET: startDb
graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
registerShutdownHook(graphDb);
// END SNIPPET: startDb
// START SNIPPET: transaction
try (Transaction tx = graphDb.beginTx())
{
// Database operations go here
// END SNIPPET: transaction
// START SNIPPET: addData
firstNode = graphDb.createNode();
firstNode.setProperty("message", "Hello, ");
secondNode = graphDb.createNode();
secondNode.setProperty("message", "World!");
relationship = firstNode.createRelationshipTo(secondNode, RelTypes.KNOWS);
relationship.setProperty("message", "brave Neo4j ");
// END SNIPPET: addData
// START SNIPPET: readData
System.out.print(firstNode.getProperty("message"));
System.out.print(relationship.getProperty("message"));
System.out.print(secondNode.getProperty("message"));
// END SNIPPET: readData
greeting = ((String) firstNode.getProperty("message"))
+ ((String) relationship.getProperty("message"))
+ ((String) secondNode.getProperty("message"));
// START SNIPPET: transaction
tx.success();
}
// END SNIPPET: transaction
}
// START SNIPPET: shutdownHook
private static void registerShutdownHook(final GraphDatabaseService graphDb)
{
// 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()
{
graphDb.shutdown();
}
});
}
// END SNIPPET: shutdownHook
}
我不想用別的,除了內置的瀏覽器中的Neo4j的。 我應該如何繼續?
在此先感謝。
撇開db_path(我在這裏把星星放在一個通用名稱中),我做了你的建議。似乎db正在工作,但仍然沒有我的節點的可視化表示。 :S – harris21 2015-02-08 21:58:56
而且您必須運行查詢來查看您的節點。但只有當你做到以上。 – 2015-02-09 08:09:24
我做了上述,並嘗試使用neo4j默認爲所有節點提供的MATCH n RETURN n LIMIT 25。即使節點設置正確,我的回報也是0。 – harris21 2015-02-09 12:52:03