参考文档:
https://blog.csdn.net/weixin_42584156/article/details/122786519
https://zhuanlan.zhihu.com/p/334634161
一、linux环境neo4j部署
默认账号密码:neo4j/neo4j #解压缩 tar -zxvf neo4j-community-3.5.31-unix.tar.gz #修改配置文件 vim ./conf/neo4j.conf # 允许远程访问 dbms.connectors.default_listen_address=0.0.0.0 # 开启bolt服务,默认端口7687 dbms.connector.bolt.listen_address=:7687 # 开启http服务,默认端口7474 dbms.connector.http.listen_address=:7474 # 开启https服务,默认端口7473 dbms.connector.https.listen_address=:7473 cd neo4j-community-3.5.25/bin #前台启动命令: ./neo4j console #后台启动命令 ./neo4j start #状态 ./neo4j status #停止 ./neo4j stop #重启 ./neo4j restart #http访问 http://yourip:7474 #重置密码 connect:bolt://yourip:7687/ username:* password:*
二、 java api操作neo4j
1.引入驱动包
<dependency> <groupId>org.neo4j.driver</groupId> <artifactId>neo4j-java-driver</artifactId> <version>4.2.0</version> </dependency>
2.java api
public class Neo4jDemo { public static void main(String[] args) { { Driver driver = GraphDatabase.driver("bolt://hw-node4:7687", AuthTokens.basic("neo4j", "****")); Session session = driver.session(); session.run("CREATE (a:Person {name: {name}, title: {title}})", parameters("name", "Dog", "title", "King")); Result result = session.run("MATCH (a:Person) WHERE a.name = {name} " + "RETURN a.name AS name, a.title AS title", parameters("name", "Dog")); while (result.hasNext()) { Record record = result.next(); System.out.println(record.get("title").asString() + " " + record.get("name").asString()); } session.close(); driver.close(); } } }