这是我的代码。输出来自控制台,但它没有在浏览器中反映出来。请给我建议解决方案。
`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();
}
} `
答案 0 :(得分:0)
您使用的方法是“嵌入式”方法,当此代码正在运行时,“file_path”中的db被程序占用,因此,您无法使用该db启动neo4j服务器。 如果你芬兰的程序,你可以在neo4j服务器午餐,看看浏览器上的点头。
我强烈建议您阅读有关neo4j“bolt driver”和“unmanaged extension”的文章