注:網上找了許多教程,發現都不太適合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)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
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); } } |
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:https://blog.csdn.net/u014451076/article/details/50997701