addConnectionOptions
(To be removed) Add JDBC driver-specific connection options
The addConnectionOptions
function will be removed in a future
release. Use the setoptions
function instead. For details, see Version History.
Description
adds JDBC driver-specific connection options using the opts
= addConnectionOptions(opts
,Option1,OptionValue1,...,OptionN,OptionValueN
)JDBCConnectionOptions
object opts
.
Examples
Add Driver-Specific Connection Option
Create a JDBC data source for a Microsoft® SQL Server® database, configure the data source by setting JDBC connection options, set an additional JDBC driver-specific option, 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 nameDataSourceName
— Name of the data sourceDatabaseName
— Name of the databaseServer
— Name of the database serverPortNumber
— Port numberAuthType
— Authentication typeJDBCDriverLocation
— 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 the database connection is successful.
username = ""; password = ""; status = testConnection(opts,username,password)
status = logical
1
Save the configured data source.
saveAsJDBCDataSource(opts)
Input Arguments
opts
— JDBC connection options
JDBCConnectionOptions
object
JDBC connection options, specified as a JDBCConnectionOptions
object.
Option1,OptionValue1,...,OptionN,OptionValueN
— JDBC driver-specific options
name-value pair arguments
JDBC driver-specific options, specified as one or more name-value pair arguments.
Option
is a character vector or string scalar that specifies the
name of a JDBC driver-specific connection option. OptionValue
specifies the value of the connection option. OptionValue
can be a
character vector, string scalar, logical scalar, or numeric scalar. You can specify any
connection option allowed by your JDBC driver. Consult your JDBC driver documentation
for the available connection options.
Note
You can specify a JDBC driver-specific connection option in two ways: using this input argument or using the database connection URL. If you specify the same option with different values in both the input argument and URL, the JDBC driver implementation defines which value takes precedence. For maximum portability, specify a JDBC driver-specific connection option in only one of these ways.
Example: 'useSSL',true
specifies that the database connection uses
SSL authentication.
Output Arguments
opts
— JDBC connection options
JDBCConnectionOptions
object
JDBC connection options, returned as a JDBCConnectionOptions
object.
Alternative Functionality
App
You can add 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 R2019bR2020b: addConnectionOptions
function will be removed
The addConnectionOptions
function will be removed in a future
release. Use the setoptions
function instead. Some differences between the workflows might require updates to your
code.
Use the setoptions
function with the SQLConnectionOptions
object to set JDBC driver-specific connection
options.
In prior releases, you configured a JDBC data source using the JDBCConnectionOptions
object, and added options using the
addConnectionOptions
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); saveAsJDBCDataSource(opts)
Now you can set JDBC driver-specific connection options using the
setoptions
function with 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", ... 'loginTimeout',20); username = ""; password = ""; status = testConnection(opts,username,password); saveAsDataSource(opts)
Comando MATLAB
Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:
Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)