Main Content

configureJDBCDataSource

(To be removed) Configure JDBC data source

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

Description

configureJDBCDataSource opens the JDBC Data Source Configuration dialog box.

example

opts = configureJDBCDataSource('Vendor',vendor) creates a new JDBC data source for the specified database vendor.

example

opts = configureJDBCDataSource('DataSource',datasource) edits an existing JDBC data source.

Examples

collapse all

Use the configureJDBCDataSource function to open the JDBC Data Source Configuration dialog box.

configureJDBCDataSource

The JDBC Data Source Configuration dialog box opens.

JDBC Data Source Configuration dialog box with the selected Microsoft SQL Server vendor

For information about configuring JDBC data sources, see Configure Driver and Data Source.

Create, configure, test, and save a JDBC data source for a Microsoft® SQL Server® database.

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.

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.

saveAsJDBCDataSource(opts)

You can connect to the new data source using the database function or the Database Explorer app.

Input Arguments

collapse all

Database vendor, specified as one of these values:

  • 'Microsoft SQL Server'Microsoft SQL Server database

  • 'MySQL' — MySQL® database

  • 'Oracle' — Oracle® database

  • 'PostgreSQL' — PostgreSQL database

  • 'Other' — Other database

You can specify these values as either a character vector or string scalar.

Data source name, specified as a character vector or string scalar. Specify the name of an existing configured JDBC data source.

Example: "myJDBCDataSource"

Data Types: char | string

Output Arguments

collapse all

JDBC connection options, returned as a JDBCConnectionOptions object.

Alternative Functionality

App

You can open the JDBC Data Source Configuration dialog box using 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 R2019a

collapse all

R2020b: configureJDBCDataSource function will be removed

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

Update Code

Use the databaseConnectionOptions function to create an SQLConnectionOptions object.

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

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

Now you can set JDBC connection options using the databaseConnectionOptions function, and save the data source using the SQLConnectionOptions object instead.

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");
username = "";
password = "";
status = testConnection(opts,username,password);
saveAsDataSource(opts)

Also, you can open the JDBC Data Source Configuration dialog box by using the Database Explorer app.