Driver driver = GraphDatabase.driver("bolt://localhost:7687", AuthTokens.basic("username", "password")); try (Session session = driver.session()) { try (Transaction tx = session.beginTransaction()) { Node node = tx.createNode(); node.setProperty("name", "Alice"); node.setProperty("age", 25); tx.commit(); } } try (Session session = driver.session()) { try (Transaction tx = session.beginTransaction()) { Node alice = tx.findNode(label, "name", "Alice"); Node bob = tx.findNode(label, "name", "Bob"); Relationship relationship = alice.createRelationshipTo(bob, RelationshipType.withName("FRIENDS")); relationship.setProperty("since", 2010); tx.commit(); } } try (Session session = driver.session()) { try (Transaction tx = session.beginTransaction()) { Result result = tx.run("MATCH (n:Person) RETURN n.name AS name"); while (result.hasNext()) { Record record = result.next(); System.out.println(record.get("name").asString()); } tx.commit(); } }


上一篇:
下一篇:
切换中文