简体   繁体   English

使用现有数据集执行Neo4j Cypher查询(通过Java)

[英]Executing Neo4j Cypher Query (by Java) Using existing Dataset

I directly made a neo4j dataset by using neo4j console ("localhost:7474") (as you knew "graph.db") I wanna execute Cypher Query (by Java) Using this data. 我直接使用neo4j控制台(“ localhost:7474”)(如您所知的“ graph.db”)制作了neo4j数据集,我想使用此数据执行Cypher Query(通过Java)。

I already saw the example from 我已经看过以下示例

https://github.com/neo4j/neo4j/blob/master/community/cypher/src/test/java/org/neo4j/cypher/javacompat/JavaQuery.java https://github.com/neo4j/neo4j/blob/master/community/cypher/src/test/java/org/neo4j/cypher/javacompat/JavaQuery.java

I just wanna use this way but directly use existing data. 我只是想使用这种方式,而是直接使用现有数据。

How can I do this? 我怎样才能做到这一点?

If you are using Neo4j in embedded mode ie it runs within the same jvm as your application, you can access it using: 如果您以嵌入式模式使用Neo4j,即它与您的应用程序在同一jvm中运行,则可以使用以下命令进行访问:

GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DBPATH) GraphDatabaseService graphDb =新的GraphDatabaseFactory()。newEmbeddedDatabase(DBPATH)

where DBPATH is the path to the database you created using Webadmin. 其中DBPATH是使用Webadmin创建的数据库的路径。 You can find that path in your neo4j install directory/conf/neo4j-server.properties (The property name is org.neo4j.server.database.location) 您可以在neo4j安装目录/conf/neo4j-server.properties中找到该路径(属性名称为org.neo4j.server.database.location)。

Once you have instantiated your graphDb, you can execute Cypher queries as described in http://docs.neo4j.org/chunked/stable/tutorials-cypher-java.html 实例化graphDb后,您可以按照http://docs.neo4j.org/chunked/stable/tutorials-cypher-java.html中的说明执行Cypher查询。

If you are not using Neo4j in embedded mode and want to connect to the existing server running on port 7474, you can use the java rest binding: https://github.com/neo4j/java-rest-binding/ 如果您不以嵌入式模式使用Neo4j,并且想连接到在端口7474上运行的现有服务器,则可以使用java rest绑定: https : //github.com/neo4j/java-rest-binding/

I wrote this few months ago. 我几个月前写的。 It's very minimalist in order to be easy to understand ! 为了易于理解,它非常简约! https://github.com/bendaizer/neo4j_cypher_java_template https://github.com/bendaizer/neo4j_cypher_java_template

You just need to give the path to your database directory (with you data), and your cypher query. 您只需要提供数据库目录的路径(包含数据)和密码查询即可。 I didn't had time to write something better, so you need to recompile for each new query ! 我没有时间写出更好的东西,因此您需要为每个新查询重新编译!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM