Main Content

JDBCConnectionOptions

(To be removed) Define JDBC connection options for database

The JDBCConnectionOptions object will be removed in a future release. Use the SQLConnectionOptions object instead. For details, see Compatibility Considerations.

Description

The JDBCConnectionOptions object enables you to configure a JDBC data source and set JDBC connection options.

Creation

Create a JDBCConnectionOptions object with the configureJDBCDataSource function.

Properties

expand all

All Databases

JDBC driver location, specified as a character vector or string scalar. Specify the full path to the JDBC driver file, including the name of the file.

Example: "C:\drivers\sqljdbc4.jar"

Data Types: char | string

This property is read-only.

Database vendor, specified as a character vector.

Example: 'MySQL'

Data Types: char

Data source name, specified as a character vector or string scalar.

Example: "mydatasource"

Data Types: char | string

Common Properties for Microsoft SQL Server, MySQL, Oracle, and PostgreSQL Databases

Database server name or address, specified as a character vector or string scalar.

Data Types: char | string

Server port number where the server is listening, specified as a numeric scalar. The default value is based on the database vendor:

  • Microsoft® SQL Server® — 1433

  • MySQL® — 3306

  • Oracle® — 1521

  • PostgreSQL — 5432

Data Types: double

Database name on the server, specified as a character vector or string scalar.

Example: "mydatabase"

Data Types: char | string

Microsoft SQL Server Database Only

Authentication type, specified as one of these values:

  • 'Server'Microsoft SQL Server authentication

  • 'Windows' — Windows® authentication

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

Oracle Database Only

Driver type, specified as one of these values:

  • 'thin' — Thin driver

  • 'oci' — Windows authentication

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

Other Databases

JDBC driver name, specified as a character vector or string scalar that refers to the Java® driver that implements the java.sql.Driver interface.

For details about the JDBC driver name, consult your database driver documentation.

Data Types: char | string

Database connection URL, specified as a character vector or string scalar for the vendor-specific URL. This URL is typically constructed using connection properties such as the server name, port number, and database name.

For details about the database connection URL, consult your database driver documentation.

Data Types: char | string

Object Functions

setConnectionOptions(To be removed) Set JDBC connection options
addConnectionOptions(To be removed) Add JDBC driver-specific connection options
rmConnectionOptions(To be removed) Remove JDBC driver-specific connection options
testConnection(To be removed) Test JDBC data source connection
saveAsJDBCDataSource(To be removed) Save JDBC data source

Examples

collapse all

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.

Compatibility Considerations

expand all

Not recommended starting in R2020b

Introduced in R2019b