Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在使用EmbeddedJava程序创建的neo4j web界面上查看节点_Java_Neo4j_Cypher - Fatal编程技术网

无法在使用EmbeddedJava程序创建的neo4j web界面上查看节点

无法在使用EmbeddedJava程序创建的neo4j web界面上查看节点,java,neo4j,cypher,Java,Neo4j,Cypher,我能够成功运行Embeddedjava程序。但是当我通过localhost打开neo4j接口时,我的节点没有得到反映。供您参考 我对neo4j-server.properties做了以下更改 org.neo4j.server.database.location=C:/neo4j-community-1.9.6/data/graph.db/ org.neo4j.server.webadmin.data.uri=C:/neo4j-community-1.9.6/data/graph.db/ 这与我

我能够成功运行Embeddedjava程序。但是当我通过localhost打开neo4j接口时,我的节点没有得到反映。供您参考

我对neo4j-server.properties做了以下更改

org.neo4j.server.database.location=C:/neo4j-community-1.9.6/data/graph.db/
org.neo4j.server.webadmin.data.uri=C:/neo4j-community-1.9.6/data/graph.db/
这与我在代码中使用的DB_路径相同

每次我运行程序时,仪表板上的计数都会增加2(我在程序中创建了2个节点)

START root=node(*)
 return count(root)
它给我的答案是0

另外,我注意到在运行java程序时不会生成数据/密钥库文件。它只有在通过localhost:7474启动接口时才会生成。这有什么关系吗

Java代码

import java.io.File;
import java.io.IOException;

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;
import org.neo4j.kernel.impl.util.FileUtils;
import  org.neo4j.kernel.StoreLocker;


public class EmbeddedNeo4j
{
private static final String DB_PATH = "C://neo4j-community-1.9.6//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 )
{
    EmbeddedNeo4j hello = new EmbeddedNeo4j();
    hello.createDb();
    hello.removeData();
    hello.shutDown();
}

    void createDb()
{
   // clearDb();
    // START SNIPPET: startDb
    graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
   // registerShutdownHook( graphDb );
    // END SNIPPET: startDb

    // START SNIPPET: transaction
    Transaction tx=null;
    try
    {
         tx= graphDb.beginTx();
         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" ) );
                   tx.success();
    }
    catch(Exception e)
    {
    tx.failure();
    }


    finally
    {
        // Database operations go here
        // END SNIPPET: transaction
        // START SNIPPET: addData


        // START SNIPPET: transaction

        tx.finish();
    }
    // END SNIPPET: transaction
}

   private void clearDb()
   {
    try
    {
        FileUtils.deleteRecursively( new File(DB_PATH) );
    }
    catch ( IOException e )
    {
        throw new RuntimeException( e );
    }
}

void removeData()
{
    Transaction tx=null;
    try 
    {

     tx = graphDb.beginTx() ;
     firstNode.getSingleRelationship( RelTypes.KNOWS, Direction.OUTGOING ).delete();
        firstNode.delete();
        secondNode.delete();
         tx.success();
}
catch(Exception e)
{
tx.failure();
}

finally

    {
        // START SNIPPET: removingData
        // let's remove the data

        // END SNIPPET: removingData


        tx.finish();
    }
}

void shutDown()
{
    System.out.println();
    System.out.println( "Shutting down database ..." );
    // START SNIPPET: shutdownServer
    graphDb.shutdown();
    // END SNIPPET: shutdownServer
}

// 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
 }

您正在创建DB,然后调用removeData。

如果您的问题是关于webadmin,当查询计数所有节点显示为0时,显示增加了2个节点,那么您应该忽略webadmin节点计数。这并不是真正的节点数量,而是使用中的最高节点ID。询问

START root=node(*)
 return count(root)

将正确显示节点数。这是0,这是预期值,因为您的java程序创建节点,然后删除它们。

您可以共享您的java代码吗?是的。我编辑了我的问题并添加了它
START root=node(*)
 return count(root)