To connect to a database from MATLAB®, install an ODBC or JDBC driver and create a data source. For details about driver installation and data source setup, see Configuring Driver and Data Source. If you do not have an installed database and want to store relational data quickly, you can use the MATLAB interface to SQLite. For details, see Working with MATLAB Interface to SQLite.
You can connect to a database using the Database Explorer or the command line. These two options enable you to perform different actions. For details about deciding which option to use, see Connection Options.
Use these steps as a general workflow for creating a database connection by using buttons in the toolstrip.
In the Data Source section of the Database Explorer tab, click Configure Data Source and select the appropriate option for configuring an ODBC or JDBC data source.
In the Connections section, click Connect and select the configured data source to create a database connection.
To close the database connection, in the Connections section, click Close Connection. If multiple connections are open, close the database connection of your choice by selecting the corresponding data source from the Close Connection list.
Use these steps as a general workflow for creating a database connection at the command line.
Configure an ODBC data source using the configureODBCDataSource
function, or configure a JDBC data
source using the configureJDBCDataSource
function.
Create a database connection using the database
function.
Close the database connection using the close
function.
After deciding between the Database Explorer app and the command line, connect to your database by following the steps for the corresponding database and driver type, as given in this list.
ODBC
JDBC
ODBC
JDBC
ODBC
JDBC
ODBC
JDBC
JDBC
No driver or database installation is required. To create an
SQLite connection, use sqlite
to create a new
SQLite database file or connect to an existing SQLite database
file.
For an example of how to connect to a database that is not listed here, see Other ODBC-Compliant or JDBC-Compliant Databases.
close
| configureJDBCDataSource
| configureODBCDataSource
| database