Main Content

rmConnectionOptions

(To be removed) Remove JDBC driver-specific connection options

The rmConnectionOptions function will be removed in a future release. Use the rmoptions function instead. For details, see Version History.

Description

opts = rmConnectionOptions(opts,option) removes a JDBC driver-specific connection option using the JDBCConnectionOptions object opts.

example

Examples

collapse all

Create a JDBC data source for a Microsoft® SQL Server® database, configure the data source by setting JDBC connection options, and set and remove an additional JDBC driver-specific option. Then, test and save the data source.

Create an SQL Server data source.

opts = configureJDBCDataSource('Vendor','Microsoft SQL Server')
opts = 

  JDBCConnectionOptions with properties:

                      Vendor: 'Microsoft SQL Server'
              DataSourceName: ''

                DatabaseName: ''
                      Server: 'localhost'
                  PortNumber: 1433
                    AuthType: 'Server'

          JDBCDriverLocation: ''

opts is a JDBCConnectionOptions object with these properties:

  • Vendor — Database vendor name

  • DataSourceName — Name of the data source

  • DatabaseName — Name of the database

  • Server — Name of the database server

  • PortNumber — Port number

  • AuthType — Authentication type

  • JDBCDriverLocation — Full path of the JDBC driver file

Configure the data source by setting the JDBC connection options for the data source SQLServerDataSource, database server dbtb04, port number 54317, full path to the JDBC driver file, and Windows® authentication.

opts = setConnectionOptions(opts, ...
    'DataSourceName','SQLServerDataSource', ...
    'Server','dbtb04','PortNumber',54317, ...
    'JDBCDriverLocation','C:\Drivers\sqljdbc4.jar', ...
    'AuthType','Windows')
opts = 

  JDBCConnectionOptions with properties:

                      Vendor: 'Microsoft SQL Server'
              DataSourceName: 'SQLServerDataSource'

                DatabaseName: ''
                      Server: 'dbtb04'
                  PortNumber: 54317
                    AuthType: 'Windows'

          JDBCDriverLocation: 'C:\Drivers\sqljdbc4.jar'

The setConnectionOptions function sets the DataSourceName, Server, PortNumber, AuthType, and JDBCDriverLocation properties in the JDBCConnectionOptions object.

Add a JDBC driver-specific connection option by using a name-value pair argument. The option specifies a timeout value for establishing the database connection. opts contains a new section of properties for the additional JDBC connection option.

opts = addConnectionOptions(opts,'loginTimeout',20)
opts = 

  JDBCConnectionOptions with properties:

                      Vendor: 'Microsoft SQL Server'
              DataSourceName: 'SQLServerDataSource'

                DatabaseName: ''
                      Server: 'dbtb04'
                  PortNumber: 54317
                    AuthType: 'Windows'

          JDBCDriverLocation: 'C:\Drivers\sqljdbc4.jar'

  Additional JDBC Connection Options:

                loginTimeout: '20'

Test the database connection with a blank user name and password. The testConnection function returns the logical 1, which indicates that the database connection is successful.

username = "";
password = "";
status = testConnection(opts,username,password)
status = logical

   1

Remove the JDBC driver-specific option. The opts object no longer contains the properties section for the additional JDBC connection options.

opts = rmConnectionOptions(opts,'loginTimeout')
opts = 

  JDBCConnectionOptions with properties:

                      Vendor: 'Microsoft SQL Server'
              DataSourceName: 'SQLServerDataSource'

                DatabaseName: ''
                      Server: 'dbtb04'
                  PortNumber: 54317
                    AuthType: 'Windows'

          JDBCDriverLocation: 'C:\Drivers\sqljdbc4.jar'

Test the database connection again.

status = testConnection(opts,username,password)
status = logical

   1

Save the configured data source.

saveAsJDBCDataSource(opts)

Input Arguments

collapse all

JDBC connection options, specified as a JDBCConnectionOptions object.

JDBC driver-specific option, specified as a character vector, string scalar, cell array of character vectors, or string array. Specify the name of one or more JDBC driver-specific connection options that you added using the addConnectionOptions function.

Example: "loginTimeout"

Data Types: char | string | cell

Output Arguments

collapse all

JDBC connection options, returned as a JDBCConnectionOptions object.

Alternative Functionality

App

You can remove JDBC driver-specific connection options by using the JDBC Data Source Configuration dialog box in the Database Explorer app. In the Data Source section of the Database Explorer tab, select Configure Data Source > Configure JDBC data source.

Version History

Introduced in R2019b

collapse all

R2020b: rmConnectionOptions function will be removed

The rmConnectionOptions function will be removed in a future release. Use the rmoptions function instead. Some differences between the workflows might require updates to your code.

Update Code

Use the rmoptions function with the SQLConnectionOptions object to remove JDBC driver-specific connection options.

In prior releases, you configured a JDBC data source using the JDBCConnectionOptions object, and removed options using the rmConnectionOptions function. For example:

opts = configureJDBCDataSource('Vendor','Microsoft SQL Server');
opts = setConnectionOptions(opts, ...
    'DataSourceName','SQLServerDataSource', ...
    'Server','dbtb04','PortNumber',54317, ...
    'JDBCDriverLocation','C:\Drivers\sqljdbc4.jar', ...
    'AuthType','Windows');
opts = addConnectionOptions(opts,'loginTimeout',20);
username = "";
password = "";
status = testConnection(opts,username,password);
opts = rmConnectionOptions(opts,'loginTimeout');
status = testConnection(opts,username,password);
saveAsJDBCDataSource(opts)

Now you can set JDBC driver-specific connection options with the SQLConnectionOptions object instead, and then remove options using the rmoptions function.

vendor = "Microsoft SQL Server";
opts = databaseConnectionOptions("jdbc",vendor);
opts = setoptions(opts, ...
    'DataSourceName',"SQLServerDataSource", ...
    'JDBCDriverLocation',"C:\Drivers\sqljdbc4.jar", ...
    'DatabaseName',"toystore_doc",'Server',"dbtb04", ...
    'PortNumber',54317,'AuthType',"Windows", ...
    'loginTimeout',20);
username = "";
password = "";
status = testConnection(opts,username,password);
opts = rmoptions(opts,'loginTimeout');
status = testConnection(opts,username,password);
saveAsDataSource(opts)