如何将我的java程序连接到neo4j localhost浏览器?

时间:2017-11-17 07:20:53

标签: java neo4j

这是我的代码。输出来自控制台,但它没有在浏览器中反映出来。请给我建议解决方案。

`package connection;  
import org.neo4j.graphdb.GraphDatabaseService;  
import org.neo4j.graphdb.Relationship;  
import org.neo4j.graphdb.RelationshipType;  
import org.neo4j.graphdb.factory.GraphDatabaseFactory;  
import org.neo4j.graphdb.factory.GraphDatabaseSettings;  
import org.neo4j.graphdb.Node;  
import java.io.File;  
public class Helloworld {  
        org.neo4j.graphdb.Node first ;
        org.neo4j.graphdb.Node second ;  
        static GraphDatabaseService gds ;  
        Relationship relation;  
        private static enum reltype implements RelationshipType {  
            KNOWS  
        }  
  

//用于创建数据库

void createdatabase(){   
            gds =new GraphDatabaseFactory().newEmbeddedDatabase(File_Path);  
            org.neo4j.graphdb.Transaction trans = gds.beginTx();  
            first = gds.createNode();  
            first.setProperty("name","shashwat");  
            second = gds.createNode();  
            second.setProperty("name","shivansh");  
            relation = first.createRelationshipTo(second,reltype.KNOWS);  
            relation.setProperty("relation","friend");  
            trans.success();
  

//用于打印更新成功

        System.out.println("succeded");    
        Iterable<Node> movies = gds.getAllNodes();  
        for(Node str : movies)
        {
          System.out.println(str.getProperty("name", "shashwat"));  
        }
    }
  

//关闭

void shutdown(){  
            System.out.println("shutting in down");  
            gds.shutdown();  
            }  
            public static void main(String[] args) {
            Helloworld hw = new Helloworld();
            hw.createdatabase();
            hw.shutdown();
            }
    }  `

1 个答案:

答案 0 :(得分:0)

您使用的方法是“嵌入式”方法,当此代码正在运行时,“file_path”中的db被程序占用,因此,您无法使用该db启动neo4j服务器。 如果你芬兰的程序,你可以在neo4j服务器午餐,看看浏览器上的点头。

我强烈建议您阅读有关neo4j“bolt driver”和“unmanaged extension”的文章