Create Apache Cassandra database connection
creates a Cassandra® database connection using a data source name, user name, and password.conn = apacheCassandra(datasource,username,password)
specifies options using one or more name-value arguments. For example,
conn = apacheCassandra(username,password,Name,Value)'PortNumber',9042 creates a Cassandra database connection using the port number 9042.
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: "127.0.0.1"
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.
conn.Keyspaces
ans = 6×1 string
"employeedata"
"system"
"system_auth"
"system_distributed"
"system_schema"
"system_traces"
Close the Cassandra database connection.
close(conn)
Create a database connection to an Apache Cassandra® database with additional options using the Apache Cassandra database C++ interface. Using an additional option for request timeout, create the database connection and display the keyspaces in the database.
Create a Cassandra database connection using a blank user name and password. Specify an additional option for a request timeout of 20 seconds.
username = ""; password = ""; conn = apacheCassandra(username,password, ... 'RequestTimeout',20)
conn =
connection with properties:
Cluster: "Test Cluster"
HostAddresses: "127.0.0.1"
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.
conn.Keyspaces
ans = 6×1 string
"employeedata"
"system"
"system_auth"
"system_distributed"
"system_schema"
"system_traces"
Close the Cassandra database connection.
close(conn)
datasource — Data source nameData source name, specified as a character vector or string scalar. Specify the name of an existing data source.
Example: "myDataSource"
Data Types: char | string
username — User nameUser name, specified as a character vector or string scalar. If the cluster requires
authentication, use the username input argument for the user
name.
Data Types: char | string
password — PasswordPassword, specified as a character vector or string scalar. If the cluster requires
authentication, use the password input argument for the
password.
Data Types: char | string
Specify optional
comma-separated pairs of Name,Value arguments. Name is
the argument name and Value is the corresponding value.
Name must appear inside quotes. You can specify several name and value
pair arguments in any order as
Name1,Value1,...,NameN,ValueN.
conn =
apacheCassandra(username,password,'SSLEnabled',true,'RequestTimeout',15) creates
a Cassandra database connection with SSL encryption enabled and a request timeout of 15
seconds.'ContactPoints' — Contact points"localhost" (default) | character vector | string scalar | cell array of character vectors | string arrayContact points, specified as a character vector, string scalar, cell array of character vectors, or string array. Contact points are host addresses for one node or host addresses for multiple nodes in the Cassandra cluster. Specify a string scalar for one node. Or, specify a string array for multiple nodes.
You can specify a local host or the IP address of a different machine in the Cassandra cluster.
When you specify multiple nodes, if the connection to one host fails, then the
apacheCassandra function connects to the other nodes in the cell array
or string array until a connection succeeds. If a connection attempt fails for all
specified nodes, the function displays an error message. If one or more nodes are not
available, enter multiple nodes in the cell array or string array to increase the
likelihood of a successful connection.
Data Types: char | string | cell
'PortNumber' — Port number9042 (default) | positive numeric scalarPort number for connection to the host, specified as a positive numeric scalar.
Data Types: double
'SSLEnabled' — SSL-enabled connectionfalse (default) | trueSSL-enabled connection, specified as the value false or true. Setting this argument to true creates an SSL-enabled connection to the Cassandra database.
Data Types: logical
'LoginTimeout' — Login timeout5 (default) | positive numeric scalarLogin timeout, specified as a positive numeric scalar. The login timeout specifies the number of seconds that the C++ driver waits while trying to connect to the Cassandra database before throwing an error.
Data Types: double
'RequestTimeout' — Request timeout12 (default) | positive numeric scalarThis property is read-only.
Request timeout, specified as a positive numeric scalar. The request timeout indicates the number of seconds the database waits to return a CQL query before throwing an error.
Data Types: double
conn — Apache Cassandra database connectionconnection objectApache Cassandra database connection, returned as a connection
object.
close | columninfo | executecql | isopen | partitionRead | tablenames | upsertYou have a modified version of this example. Do you want to open this example with your edits?