java neo4j配置_neo4j安装配置入门教程

注:网上找了许多教程,发现都不太适合0基础的用户,所以就自己写了一下。

推荐使用1.x版本,经测试2.3.3大量函数被遗弃。

安装启动

官网下载tar包

解压,进入bin下,运行./neo4j

在url中打开localhost:7474即可使用

配置

数据库的location设置。

conf/neo4j-server.properties中第14行org.neo4j.serve.database.location=进行修改

使用

1.web可视化neo4j的工具是webadmin,打开方式:url中打开local/webadmin,即可使用

注:代码修改数据库,似乎需要每次重启neo4j才能在webadmin中显示,也有可能是数据同步慢

2.简单实例(java操作neo4j)

package neo4j;

import java.io.File;

import java.io.IOException;

import javax.management.relation.Relation;

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.io.fs.FileUtils;

public class test {

public enum RelTypes implements RelationshipType{

KNOWS

}

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 example before it's completed)

/*为了确保neo4j数据库的正确关闭,我们可以添加一个关闭钩子方法

* registerShutdownHook。这个方法的意思就是在jvm中增加一个关闭的

* 钩子,当jvm关闭的时候,会执行系统中已经设置的所有通过方法

* addShutdownHook添加的钩子,当系统执行完这些钩子后,jvm才会关闭。

* 所以这些钩子可以在jvm关闭的时候进行内存清理、对象销毁等操作。*/

Runtime.getRuntime().addShutdownHook( new Thread()

{

@Override

public void run()

{

graphDb.shutdown();

}

} );

}

public static void main(String[] args) throws IOException {

FileUtils.deleteRecursively( new File( "db" ) );

GraphDatabaseService graphdb=new GraphDatabaseFactory().newEmbeddedDatabase("db");

Relationship relationship;

Transaction tx=graphdb.beginTx();

try{

Node node1=graphdb.createNode();

Node node2=graphdb.createNode();

node1.setProperty("message", "Hello");

node2.setProperty("message", "World");

relationship = node1.createRelationshipTo(node2, RelTypes.KNOWS);

relationship.setProperty("message", "brave neo4j");

tx.success();

System.out.println("successfully");

}

finally{

tx.finish();

}

registerShutdownHook(graphdb);

}

}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值