Connection Options

You can connect to a database in various ways using Database Toolbox™. If you have access to a database, create a data source. Then, you can connect to the database either by using the Database Explorer app or the command line. 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.

Creating or Connecting to Data Source

If you already have a database driver installed, you can create a data source. For an ODBC driver, open the Microsoft® ODBC Data Source Administrator dialog box by using the configureODBCDataSource function. For a JDBC driver, open the JDBC Data Source Configuration dialog box by using the configureJDBCDataSource function. For examples, see Configuring Driver and Data Source. Otherwise, see Driver Installation for information about installing your driver. If your data source is already defined, then you are ready to connect to your database. For details, see Connecting to Database. After establishing a connection, you can explore the database and view data using the Database Explorer app or the command line. For details, see Data Import Using Database Explorer App or Command Line.

Defining Operating System Authentication

Operating system authentication enables you to connect to a database using your operating system user account. The operating system performs user validation, and the database does not require a different user name and password. Operating system authentication facilitates the maintenance of database access credentials. For example, Windows® provides operating system authentication that can be configured to work with a Microsoft SQL Server® database. For details about Microsoft SQL Server Windows authentication, see Set up the operating system authentication.

Connection Options

Use this table to choose your best connection option.

Connection Option

Why Use This Option?

Database Explorer app

Use the Database Explorer app to:

  • Visually inspect the structure, or schema, of a database.

  • Assess the general size of a database by viewing the database structure.

  • Select the data in a table and import it into a MATLAB variable.

  • Generate a MATLAB script.

  • Generate an SQL query.

Command line

Use the command line to:

  • Import data from a database into MATLAB.

  • Export data from MATLAB into a database.

  • Work with large amounts of data.

  • Run SQL queries stored in text files.

  • Run stored procedures and functions.

There are multiple options to connect to your database using the command line. Use this table to choose your best connection option.

Command-Line Connection Option

Why Use This Option?

ODBC connection

Connect to your database with maximum performance.

JDBC connection

Achieve maximum platform independence.

SQLite connection

Import data without installing a database or a driver. For details, see Working with MATLAB Interface to SQLite.

You can create multiple connections at a time to the same database or a different database. For creating multiple connections using the Database Explorer app, see Create SQL Queries Using Database Explorer App. Or, you can use the database function to create multiple connections at the command line.

See Also

Related Topics