private static int runQuery(Statement statement, String query) {
    ResultSet rs = null;
    int result = 0;
    try {
      rs = statement.executeQuery(query);

      if (rs != null) {
        while (rs.next()) {
          result = rs.getInt(1);
        }
      }

    } catch (SQLException e) {
      warning("Exception occurred during topology request tables check: ", e);
    } finally {
      if (rs != null) {
        try {
          rs.close();
        } catch (SQLException e) {
          LOG.error("Exception occurred during result set closing procedure: ", e);
        }
      }
    }
    return result;
  }
This method checks if all hosts from hosts table
has related host state info in hoststate table.
If not then we are showing error.
ambari-server/src/main/java/org/apache/ambari/server/checks/DatabaseConsistencyCheckHelper.java