简体   繁体   中英

How to connect with neo4j server using java?

I am a newbie to neo4j serve. I started working on neo4j server through direct cypher queries on neo4j local server queries of creating node, label, node properties, relationship between nodes etc.. I have little bit ideas on how are things working.

Problem that I am facing is that I have stucked in connecting with neo4j server using java.

Codes I am currently trying to use to connect with local server are:-

GraphDatabaseService db = new RestGraphDatabase(" http://localhost:7474/db/data ");

RestGraphDatabase graphDb = new RestGraphDatabase(" http://localhost:7474/db/data ");

But every time I get the error 500 Server Error The call failed on the server; see server log for details

Unable to find out the reason. I am perfectly connected to my local server.But still problem remains the same.

I have succeeded in connecting with server and doing basic operation using rest api. But Still finding difficult for searching in it.That is why wanted help in using the neo4j jar files for the functionality of neo4j graph db.

Links I am following:- RestApi

Embedded graphDb

RestServer

I recommend to check out the JDBC driver.

See http://neo4j.com/developer/java

You need to add the jar file that helps you in connecting with neo4j server. You can find the driver/jar file from https://github.com/larusba/doc2graph/releases/tag/v1.0.0

After downloading the file add it to your project using project preferences. Then, go using the below code to starting working on it!

Connection con = DriverManager.getConnection("jdbc:neo4j:bolt://localhost");

    try (Statement stmt = con.createStatement()) {
        ResultSet rs = stmt.executeQuery("MATCH (n:User) RETURN n.name");
        while (rs.next()) {
            System.out.println(rs.getString("n.name"));
        }
    }
    con.close();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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