testConnection
Syntax
Description
tests the Apache Cassandra® database connection specified by the status = testConnection(opts,username,password)CassandraConnectionOptions object opts, a user name, and a
password.
Examples
Configure an Apache™ Cassandra® database connection by creating a Cassandra data source, setting the Cassandra connection options, and saving the data source.
Create a Cassandra data source for a Cassandra database connection.
vendor = "Cassandra"; opts = databaseConnectionOptions("native",vendor)
opts =
CassandraConnectionOptions with properties:
DataSourceName: ""
Vendor: "Cassandra"
ContactPoints: "localhost"
PortNumber: 9042
SSLEnabled: false
LoginTimeout: 5
RequestTimeout: 12
opts is an CassandraConnectionOptions object with these properties:
DataSourceName— Name of the data sourceVendor— Database vendor nameContactPoints— Contact pointsPortNumber— Port numberSSLEnabled— SSL-enabled connectionLoginTimeout— Login timeoutRequestTimeout— Request timeout
Configure the data source by setting the Cassandra connection options for the data source CassandraDataSource, local host address for one node in the cluster, port number 9042, SSL encryption that is disabled, login timeout of 5 seconds, and request timeout of 12 seconds.
opts = setoptions(opts, ... "DataSourceName","CassandraDataSource", ... "ContactPoints","localhost","PortNumber",9042, ... "SSLEnabled",false,"LoginTimeout",5, ... "RequestTimeout",12)
opts =
CassandraConnectionOptions with properties:
DataSourceName: "CassandraDataSource"
Vendor: "Cassandra"
ContactPoints: "localhost"
PortNumber: 9042
SSLEnabled: false
LoginTimeout: 5
RequestTimeout: 12
The setoptions function sets the DataSourceName, ContactPoints, PortNumber, SSLEnabled, LoginTimeout, and RequestTimeout properties in the CassandraConnectionOptions object.
Test the database connection with a blank user name and password. The testConnection function returns the logical 1, which indicates the database connection is successful.
username = ""; password = ""; status = testConnection(opts,username,password)
status = logical
1
Save the configured data source.
saveAsDataSource(opts)
Create and configure a Cassandra data source to a Cassandra database. Test the database connection to the Cassandra data source and retrieve the error message.
Create a Cassandra data source for a Cassandra database connection.
vendor = "Cassandra"; opts = databaseConnectionOptions("native",vendor)
opts =
CassandraConnectionOptions with properties:
DataSourceName: ""
Vendor: "Cassandra"
ContactPoints: "localhost"
PortNumber: 9042
SSLEnabled: false
LoginTimeout: 5
RequestTimeout: 12
opts is a CassandraConnectionOptions object
with these properties:
DataSourceName— Name of the data sourceVendor— Database vendor nameContactPoints— Contact pointsPortNumber— Port numberSSLEnabled— SSL-enabled connectionLoginTimeout— Login timeoutRequestTimeout— Request timeout
Configure the data source by setting the Cassandra connection options for the data
source CassandraDataSource, local host address for one node in the
cluster, port number 1500, SSL encryption that is disabled, login
timeout of 5 seconds, and request timeout of 12 seconds. In this case, the port number
is invalid.
opts = setoptions(opts, ... "DataSourceName","CassandraDataSource", ... "ContactPoints","localhost","PortNumber",1500, ... "SSLEnabled",false,"LoginTimeout",5, ... "RequestTimeout",12)
opts =
CassandraConnectionOptions with properties:
DataSourceName: "CassandraDataSource"
Vendor: "Cassandra"
ContactPoints: "localhost"
PortNumber: 1500
SSLEnabled: false
LoginTimeout: 5
RequestTimeout: 12
The setoptions function sets the
DataSourceName, ContactPoints,
PortNumber, SSLEnabled,
LoginTimeout, and RequestTimeout properties in
the CassandraConnectionOptions object.
Test the database connection using a blank user name and password. The
testConnection function returns the logical 0,
which indicates the database connection fails because the port number is invalid.
Retrieve and display the error message for the failed connection.
username = ""; password = ""; [status,message] = testConnection(opts,username,password)
status =
logical
0
message =
'Cassandra exception: Underlying connection error: Connect error 'connection refused''
Input Arguments
Database connection options, specified as a CassandraConnectionOptions
object.
Username required to access the database, specified as a character
vector or string scalar. If no username is required, specify an
empty value "". Provide this username if you
do not store it as part of the data source when using the
Database Explorer app to make a connection.
Password required to access the database, specified as a character vector or string scalar. If
no password is required, specify an empty value
"". Provide this password if you
do not store it as part of the data source when using the
Database Explorer app to make a connection.
Data Types: char | string
Output Arguments
Connection status, returned as a logical true if the connection
test passes or false if the connection test fails.
Error message, returned as a character vector. If the connection test passes, then the error message is an empty character vector. Otherwise, the error message contains text from the failed database connection.
Version History
Introduced in R2021a
See Also
Objects
Functions
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)