Java 使用 neo4j-java-driver操作neo4j ---操作步骤

1:使用maven依赖管理, 加入maven驱动包


	org.neo4j.driver
	neo4j-java-driver
	1.2.2


2:
(1) 建立连接 GraphDatabase.driver()
(2) session创建会话 Session session = driver.session()
(3)执行CQL 插入语句 session.run().paramters()
(4)执行CQL查询语句 StatementResult result = session.run().paramters()
(5) 循环打印出查询信息

 while ( result.hasNext() )
        {
            Record record = result.next();
            System.out.println( record.get( "title" ).asString() + " " + record.get( "name" ).asString() );
        }
 

(6)关闭连接
session.close();
driver.close();

package com.neo4j.conn;

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

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        Driver driver = GraphDatabase.driver( "bolt://localhost:7687", AuthTokens.basic( "neo4j", "" ) );
        Session session = driver.session();
        session.run( "CREATE (a:Person {name: {name}, title: {title}})",
                parameters( "name", "Arthur001", "title", "King001" ) );

        StatementResult result = session.run( "MATCH (a:Person) WHERE a.name = {name} " +
                                              "RETURN a.name AS name, a.title AS title",
                parameters( "name", "Arthur001" ) );
        while ( result.hasNext() )
        {
            Record record = result.next();
            System.out.println( record.get( "title" ).asString() + " " + record.get( "name" ).asString() );
        }
        session.close();
        driver.close();
    }
}
 

你可能感兴趣的:(Neo4j图数据库)