简体   繁体   English

neo4j:以Java发送的有限查询

[英]neo4j : Limited queries sent in java

For a website developed under Tomcat, I connect my program to a database neo4j. 对于在Tomcat下开发的网站,我将程序连接到数据库neo4j。 Connection is done through jdbc. 通过jdbc完成连接。 My program is right now local, and the database is on a remote server. 我的程序现在是本地的,数据库在远程服务器上。 When I start Tomcat, it first check if specifics nodes are presents, and if not, it creates them. 当我启动Tomcat时,它首先检查是否存在特定的节点,如果不存在,则会创建它们。 There are about 135 nodes. 大约有135个节点。 Problem : After about ten, the program stops, and stay in something like an infinite loop. 问题:大约十点之后,程序停止运行,并停留在无限循环之类的状态。 I assume I should close something, but what? 我想我应该关闭一些东西,但是呢? Here is my code : 这是我的代码:

private ResultSet sendCommand(String command) throws SQLException
    {
        try(Statement statement = _neo4jConnection.createStatement())
        {
            return statement.executeQuery(command);
        }
    }

and a function to call this code (all functions are based on the same structure) 和一个调用此代码的函数(所有函数都基于相同的结构)

public static Long createNode(NodeLabel labelName)
    {
        try
        {
            ResultSet rs = getInstance().sendCommand("CREATE (n:"+labelName+") RETURN id(n)");
            Long result= rs.next()?rs.getLong("id(n)"):null;
            rs.close();
            return result;
        } catch (SQLException e) {
            e.printStackTrace();
            return null;
        }       
    }

in my latest experiment I reused the same statement multiple times, not sure that is the best way but it seems to work good, too. 在我最新的实验中,我多次重用了同一条语句,虽然不确定这是最好的方法,但似乎也能很好地工作。

https://github.com/peterneubauer/blogs/tree/master/csv_jdbc , code at https://github.com/peterneubauer/blogs/blob/master/csv_jdbc/src/test/java/org/neo4j/jdbctest/JDBCTest.java https://github.com/peterneubauer/blogs/tree/master/csv_jdbc ,代码位于https://github.com/peterneubauer/blogs/blob/master/csv_jdbc/src/test/java/org/neo4j/jdbctest/ JDBCTest.java

The only solution I found was to regularly disconnect and reconnect to the database (After about 20 statements). 我发现的唯一解决方案是定期断开连接并重新连接到数据库(大约20条语句之后)。 This is awful, but it works. 这太可怕了,但是行得通。 Well, however, I gave up with jdbc for neo4j, too much issues, and catastrophical performances (about 1s to get one simple data), what occures still more issues! 好吧,但是,我放弃了针对neo4j的jdbc,太多的问题和灾难性的性能(获取一个简单数据大约需要1s),发生了更多的问题!

Anyway, Thanks for your help 无论如何,谢谢您的帮助

Niko 尼可

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

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