java api操作
java api操作neo4j框架类似于创建jdbc连接(图数据也是数据库嘛)
public static void main(String[] args) {
//获取neo4j的驱动
Driver driver = GraphDatabase.driver("bolt://172.16.2.207:7687", AuthTokens.basic("neo4j", "neo4j123"));
Session session = null;
Transaction transaction = null;
try {
//获取会话 connection
session = driver.session();
//开启事务
transaction = session.beginTransaction();
//创建Statement
Statement query = new Statement(
"CREATE (a:Greeting) SET a.message = $message RETURN a.message + ', from node ' + id(a)",
Values.parameters("message", "testDriver"));
StatementResult result = transaction.run(query);
//提交事务
transaction.success();
String greeting = result.single().get(0).asString();
System.out.println(greeting);
}catch (Exception e){
//事务回滚
transaction.rollbackAsync();
}
finally {
//关闭相关资源
if(session.isOpen()){
session.close();
}
if(transaction.isOpen()){
transaction.close