(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.
The JDBCConnectionOptions
object enables you to configure a JDBC
data source and set JDBC connection options.
Create a JDBCConnectionOptions
object with the configureJDBCDataSource
function.
JDBCDriverLocation
— JDBC driver locationJDBC 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
Vendor
— Database vendorThis property is read-only.
Database vendor, specified as a character vector.
Example:
'MySQL'
Data Types: char
DataSourceName
— Data source nameData source name, specified as a character vector or string scalar.
Example: "mydatasource"
Data Types: char
| string
Server
— Database server name or address'localhost'
(default) | character vector | string scalarDatabase server name or address, specified as a character vector or string scalar.
Data Types: char
| string
PortNumber
— Server port number where the server is listeningServer 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
DatabaseName
— Database nameDatabase name on the server, specified as a character vector or string scalar.
Example:
"mydatabase"
Data Types: char
| string
AuthType
— Authentication type'Server'
(default) | 'Windows'
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.
DriverType
— Driver type'thin'
(default) | 'oci'
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.
Driver
— JDBC driver nameJDBC 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
URL
— Database connection URLDatabase 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
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 |
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.
JDBCConnectionOptions
object will be removedNot recommended starting in R2020b
The JDBCConnectionOptions
object will be removed in a future release.
Use the SQLConnectionOptions
object instead. Some differences between the workflows
might require updates to your code.
Use the SQLConnectionOptions
object to set JDBC connection
options.
In prior releases, you configured a JDBC data source using 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 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)