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 Version History.
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
All Databases
JDBCDriverLocation
— JDBC driver location
character vector | string scalar
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
Vendor
— Database vendor
character vector
This property is read-only.
Database vendor, specified as a character vector.
Example:
'MySQL'
Data Types: char
DataSourceName
— Data source name
character vector | string scalar
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
Server
— Database server name or address
'localhost'
(default) | character vector | string scalar
Database server name or address, specified as a character vector or string scalar.
Data Types: char
| string
PortNumber
— Server port number where the server is listening
numeric scalar
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
DatabaseName
— Database name
character vector | string scalar
Database name on the server, specified as a character vector or string scalar.
Example:
"mydatabase"
Data Types: char
| string
Microsoft SQL Server Database Only
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.
Oracle Database Only
DriverType
— Driver type
'thin'
(default) | 'oci'
Driver type, specified as one of these values:
'thin'
— Thin driver'oci'
— Windows authenticationYou can specify these values as either a character vector or string scalar.
Other Databases
Driver
— JDBC driver name
character vector | string scalar
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
URL
— Database connection URL
character vector | string scalar
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
Create 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 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.
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.
Version History
Introduced in R2019bR2020b: JDBCConnectionOptions
object will be removed
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)
See Also
Objects
Functions
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)