Main Content


Apache Cassandra database connection

Since R2021a


The connection object represents an Apache Cassandra® database connection created using the Apache Cassandra database C++ interface.

After you create a connection object, you can use the object functions to import data from the Cassandra database into MATLAB®. Or, you can export data from MATLAB to the Cassandra database. You can also explore the database structure and execute Cassandra Query Language (CQL) queries.

For details about the Cassandra database, see the Apache Cassandra Documentation.


To create a connection object, use the apacheCassandra function.


expand all

This property is read-only.

Cassandra cluster name, specified as a string scalar.

Example: "Test Cluster"

Data Types: string

This property is read-only.

Host address for one node or host addresses for multiple nodes in the Cassandra cluster, specified as a string scalar for one node or string array for multiple nodes. These addresses include the addresses specified in the 'ContactPoints' name-value argument of the apacheCassandra function.

Example: "localhost/"

Data Types: string

This property is read-only.

Local data center name, specified as a string scalar. The name describes the data center that the cluster declares as local for the connection instance. The name matches the data center of the original contact point for the connection. When you set up the cluster, you define a data center for each node.

Example: "datacenter1"

Data Types: string

This property is read-only.

Keyspaces in the Cassandra database, specified as a string scalar or string array. A string scalar indicates the Cassandra database has one keyspace, and a string array indicates multiple keyspaces.

Example: ["employeedata" "system"]

Data Types: string

This property is read-only.

Request timeout, specified as a positive numeric scalar. The request timeout indicates the number of seconds to wait for the database to return a CQL query before throwing an error.

Data Types: double

Object Functions

expand all

closeClose Apache Cassandra database connection
isopenDetermine if Apache Cassandra database connection is open
columninfoRetrieve column information from Apache Cassandra database table
partitionReadImport data from partitions of Apache Cassandra database table
tablenamesList names of database tables in Apache Cassandra database
upsertInsert or update data in Apache Cassandra database
executecqlExecute CQL query on Apache Cassandra database


collapse all

Create a database connection to an Apache™ Cassandra® database using the Apache Cassandra database C++ interface. To create this connection, you must configure a Cassandra data source. For more information, see the databaseConnectionOptions function. Using a local host address, create the database connection and display the keyspaces in the database.

Create a Cassandra database connection using the configured data source CassandraDataSource and a blank user name and password.

datasource = "CassandraDataSource";
username = "";
password = "";
conn = apacheCassandra(datasource,username,password)
conn = 
  connection with properties:

            Cluster: "Test Cluster"
      HostAddresses: ""
    LocalDataCenter: "datacenter1"
     RequestTimeout: 20
          Keyspaces: [6×1 string]

conn is a connection object that contains these properties:

  • Cassandra cluster name

  • Host address

  • Local data center name

  • Keyspaces

  • Request timeout

Display the keyspaces in the Cassandra database by accessing the Keyspaces property of the connection object.

ans = 6×1 string

Close the Cassandra database connection.


Version History

Introduced in R2021a