private void query(String query) {
        Statement statement = null;
        boolean done = false;

        while(!done && open) {
            if(!open) {
                throw new ClosedException();
            }
            
            try {
                statement = connection.createStatement();
                statement.executeUpdate(query);
                done = true;
            } catch (SQLException ex) {
                if(ex.getCause() instanceof ResourceException) {
                    if(((ResourceException) ex.getCause()).getStatus().getCode() > 1000) {
                        // If we see a connection related error try to sleep for a bit
                        sleepOrClose(1000);
                    }
                }
                Logger.getLogger(Neo4jService.class.getName())
                    .log(Level.SEVERE, "Retrying to execute query", ex);
            } finally {
                if (statement != null) {
                    try {
                        statement.close();
                    } catch (SQLException ex) {
                        // Ignore
                    }
                }
            }
        }
    }