stanfordnlp/CoreNLP · error · RuntimeException

getting table count is not working!

Error message

getting table count is not working!

What it means

getTotalCount runs 'select count(*) from GoogleNgrams_<n>' and returns the first row's value. If the ResultSet has no rows (unexpected for a count query), it throws this RuntimeException, indicating the query unexpectedly returned no result.

Solutions

  1. Verify the table exists and the query is still 'select count(*) from <table>' (a count query always returns one row)
  2. Recreate the table per the class docs if it is corrupted or empty in an unexpected state
  3. Check for JDBC driver problems; try the query manually in psql
Defensive patterns

Strategy: try-catch

Validate before calling

// confirm the table exists before counting
select to_regclass('GoogleNgrams_1') is not null as ok;

Try / catch

try { int c = GoogleNGramsSQLBacked.getTotalCount(n); } catch (RuntimeException e) { log("count unavailable: " + e.getMessage()); }

Prevention

When it happens

Trigger: Calling getTotalCount on a table for which the SELECT returns an empty ResultSet — practically only when the query was rewritten, the table is a view behaving oddly, or the JDBC driver misbehaves.

Common situations: Modifying the query to something other than count(*); driver or connection issues yielding an unusable ResultSet.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/8106e7c017bd1563. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/util/GoogleNGramsSQLBacked.java:188

        stmt.execute(q);
      }
    }
  }

  /** Note that this is really really slow for ngram > 1
   * TODO: make this fast (if we had been using mysql we could have)
   * **/
  public static int getTotalCount(int ngram){
    try{
      connect();
      Statement stmt = connection.createStatement();
      String table = tablenamePrefix + ngram;
      String q = "select count(*) from " + table+";";
      ResultSet s = stmt.executeQuery(q);
      if(s.next()){
        return s.getInt(1);
      } else
        throw new RuntimeException("getting table count is not working!");
    }
    catch(SQLException e){
      throw new RuntimeException("getting table count is not working! " + e);
    }
  }

  /** Return rank of 1 gram in google ngeams if it is less than 20k. Otherwise -1. */
  public static int get1GramRank(String str) {
    String query = null;
    try{
      connect();
      str = str.trim();
      if(str.contains("'")){
        str = StringUtils.escapeString(str, new char[]{'\''},'\'');
      }

      int ngram = str.split("\\s+").length;
      if(ngram > 1)

View on GitHub (pinned to 1b7edd19c4)