Get a table (Java)

Gets a reference to a table for use with the Data API clients.

Ready to write code? See the examples for this method to get started. If you are new to the Data API, check out the quickstart.

Result

Returns a Table<T> object that corresponds to the specified table name.

This method returns a Table object even for tables that don’t exist.

Unless you specify the rowClass parameter, the table is typed as Table<Row>.

Parameters

Use the getTable method, which belongs to the com.datastax.astra.client.databases.Database class.

Method signature
Table<Row> getTable(String tableName)
Table<Row> getTable(
  String tableName,
  TableOptions tableOptions
)
<T> Table<T> getTable(Class<T> rowClass)
<T> Table<T> getTable(
  String tableName,
  Class<T> rowClass
)
<T> Table<T> getTable(
  String tableName,
  Class<T> rowClass,
  TableOptions tableOptions
)
Name Type Summary

name

String

The name of the table.

rowClass

Class<?>

Optional. A specification of the class of the table’s row object.

For an example, see Get a table and specify typing.

Default: Row, which is close to a Map object

tableOptions

TableOptions

Optional. The options for this operation. See Selected methods of TableOptions for more details.

Selected methods of TableOptions
Method Parameters Summary

keyspace()

String

Optional if you specified a working keyspace when you created the Database object. The keyspace containing the table.

Default: The working keyspace set when you created the Database object, if one was provided.

timeout()

long | Duration

Optional. A timeout, in milliseconds, for the underlying HTTP requests originating from this Table object. If not provided, the Database setting is used.

databaseAdditionalHeaders()

Map<String, String>

Optional. Specialized headers for this table, if needed, that are added to the database headers.

httpClientOptions()

HttpClientOptions

Optional. HTTP configuration overrides for this Table object.

serializer()

DataAPISerializer

Optional. A specialized serializer for this Table instance. If not provided RowSerializer is used.

Examples

The following examples demonstrate how to get a table.

Get a table

import com.datastax.astra.client.DataAPIClients;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.definition.rows.Row;

public class Example {

  public static void main(String[] args) {

    // Get an existing table
    Table<Row> table =
        DataAPIClients.clientHCD("USERNAME", "PASSWORD")
            .getDatabase("API_ENDPOINT", "KEYSPACE_NAME")
            .getTable("TABLE_NAME");
  }
}

Get a table and specify typing

Use the Class parameter to specify typing for the row.

If you don’t specify the Class parameter, the client defaults Table as the type. In this case, the working object type T is Row.class.

import com.datastax.astra.client.DataAPIClients;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.definition.columns.TableColumnTypes;
import com.datastax.astra.client.tables.mapping.Column;
import java.util.Date;
import java.util.Map;
import java.util.Set;
import lombok.Data;
import lombok.NoArgsConstructor;

public class Example {
  @Data
  @NoArgsConstructor
  public class Book {
    @Column(name = "title", type = TableColumnTypes.TEXT)
    private String title;

    @Column(name = "author", type = TableColumnTypes.TEXT)
    private String author;

    @Column(name = "number_of_pages", type = TableColumnTypes.INT)
    private Integer number_of_pages;

    @Column(name = "rating", type = TableColumnTypes.FLOAT)
    private Float rating;

    @Column(name = "genres", type = TableColumnTypes.SET, valueType = TableColumnTypes.TEXT)
    private Set<String> genres;

    @Column(
        name = "metadata",
        type = TableColumnTypes.MAP,
        keyType = TableColumnTypes.TEXT,
        valueType = TableColumnTypes.TEXT)
    private Map<String, String> metadata;

    @Column(name = "is_checked_out", type = TableColumnTypes.BOOLEAN)
    private Boolean is_checked_out;

    @Column(name = "due_date", type = TableColumnTypes.DATE)
    private Date due_date;
  }

  public static void main(String[] args) {
    // Get an existing table
    Table<Book> table =
        DataAPIClients.clientHCD("USERNAME", "PASSWORD")
            .getDatabase("API_ENDPOINT", "KEYSPACE_NAME")
            .getTable("TABLE_NAME", Book.class);
  }
}

Client reference

For more information, see the client reference.

Was this helpful?

Give Feedback

How can we improve the documentation?

© Copyright IBM Corporation 2026 | Privacy policy | Terms of use Manage Privacy Choices

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: Contact IBM