使用Java代码直接打开Neo4j图

时间:2017-04-05 20:44:38

标签: java maven neo4j graph-databases graph-visualization

我一直在尝试制作Maven-Web应用程序。我正在计算一些东西,然后我需要在我想用Neo4j显示的图表中显示它。我现在面临的问题是我能够将我的程序连接到Neo4j,但是我无法直接打开将显示图形的浏览器。

我的代码是:

   public static void main( String[] args ) throws IOException,     {
    File fileName=new File("C:/path/Documents/Neo4j/default.graphdb");
    GraphDatabaseFactory dbFactory= new GraphDatabaseFactory();
    GraphDatabaseService graphDb=dbFactory.newEmbeddedDatabase(fileName);

    try(Transaction tx=graphDb.beginTx()){


      Node ANode=graphDb.createNode(NodeType.TSpot);
      ANode.setProperty("PId", "A");


      Node BNode=graphDb.createNode(NodeType.TSpot);
      BNode.setProperty("PId", "B");


      Relationship distance = ANode.createRelationshipTo(BNode,RelationType.Distance);
      distance.setProperty("distance", 40);


      tx.success();
      System.out.println("Success");

    }
    Config noSSL = Config.build()
            .withEncryptionLevel(Config.EncryptionLevel.NONE).toConfig();

    Driver driver = GraphDatabase.driver( "bolt://localhost", AuthTokens.basic( "neo4j", "neo4j" ) , noSSL);
    Session session = driver.session();

    session.run( "MATCH (n) DETACH DELETE n" );
    StatementResult result = session.run( "MATCH (n) RETURN n" );

    session.close();
    driver.close();
    graphDb.shutdown();
     }

我得到的错误是:

 Exception in thread "main" org.neo4j.driver.v1.exceptions.AuthenticationException: The client is unauthorized due to authentication failure.
at org.neo4j.driver.internal.net.SocketResponseHandler.handleFailureMessage(SocketResponseHandler.java:71)
at org.neo4j.driver.internal.messaging.PackStreamMessageFormatV1$Reader.unpackFailureMessage(PackStreamMessageFormatV1.java:457)
at org.neo4j.driver.internal.messaging.PackStreamMessageFormatV1$Reader.read(PackStreamMessageFormatV1.java:418)
at org.neo4j.driver.internal.net.SocketClient.receiveOne(SocketClient.java:176)
at org.neo4j.driver.internal.net.SocketClient.receiveAll(SocketClient.java:170)
at org.neo4j.driver.internal.net.SocketConnection.receiveAll(SocketConnection.java:200)
at org.neo4j.driver.internal.net.SocketConnection.sync(SocketConnection.java:155)
at org.neo4j.driver.internal.net.SocketConnection.init(SocketConnection.java:117)
at org.neo4j.driver.internal.net.ConcurrencyGuardingConnection.init(ConcurrencyGuardingConnection.java:53)
at org.neo4j.driver.internal.net.SocketConnector.connect(SocketConnector.java:58)
at org.neo4j.driver.internal.net.pooling.SocketConnectionPool$ConnectionSupplier.get(SocketConnectionPool.java:203)
at org.neo4j.driver.internal.net.pooling.SocketConnectionPool$ConnectionSupplier.get(SocketConnectionPool.java:185)
at org.neo4j.driver.internal.net.pooling.BlockingPooledConnectionQueue.acquire(BlockingPooledConnectionQueue.java:92)
at org.neo4j.driver.internal.net.pooling.SocketConnectionPool.acquireConnection(SocketConnectionPool.java:136)
at org.neo4j.driver.internal.net.pooling.SocketConnectionPool.acquire(SocketConnectionPool.java:75)
at org.neo4j.driver.internal.DirectDriver.newSessionWithMode(DirectDriver.java:50)
at org.neo4j.driver.internal.BaseDriver.session(BaseDriver.java:64)
at org.neo4j.driver.internal.BaseDriver.session(BaseDriver.java:57)
at final_project.App.main(App.java:87)

我想我需要重置neo4j的密码,这是neo4j第一次运行时完成的。

0 个答案:

没有答案