Java操作Neo4j

添加依赖:

 <dependency>
       <groupId>org.neo4j.driver</groupId>
       <artifactId>neo4j-java-driver</artifactId>
       <version>1.0.0</version>
</dependency>

Java 代码:

import org.neo4j.driver.v1.*;
import static org.neo4j.driver.v1.Values.parameters;

public class test1 {
    public static  void  main(String[] args){
        Driver driver = GraphDatabase.driver(
                "bolt://localhost:7687",//或者"bolt://localhost"这样会使用默认值
                AuthTokens.basic( "neo4j", "neo4j" ) );
        Session session = driver.session();

        session.run( "CREATE (a:实体 {value: {value}})",
                parameters( "value","王菲" ) );

        StatementResult result = session.run( "MATCH (a:实体) " +
                        "RETURN a.value AS value" );
        while ( result.hasNext() )
        {
            Record record = result.next();
            System.out.println( record.get( "value" ).asString()  );
        }
        session.close();
        driver.close();
    }
}

第一次使用时误将端口号修改为7474导致异常: Stack Overflow上给出了解释
The 7474 port is the HTTP port. Since you’re using the bolt:// protocol, you should connect to the 7687 port. Or actually remove the port since it’s the default value:

猜你喜欢

转载自blog.csdn.net/u012485480/article/details/80527625