安装启动
- 官网下载tar包
- 解压,进入bin下,运行./neo4j
- 在url中打开localhost:7474即可使用
配置
- 数据库的location设置。
conf/neo4j-server.properties中第14行org.neo4j.serve.database.location=
进行修改
使用
- web可视化neo4j的工具是webadmin,打开方式:url中打开
local/webadmin
,即可使用
注:代码修改数据库,似乎需要每次重启neo4j才能在webadmin中显示,也有可能是数据同步慢 - 简单实例(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 )
{
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);
}
}