Main Content

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 Interact with Data in SQLite Database Using 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 or the Database Explorer app. You can also configure an ODBC data source by using the databaseConnectionOptions function at the command line.

  • For a JDBC driver, open the JDBC Data Source Configuration dialog box by using the Database Explorer app, or configure a JDBC data source by using the databaseConnectionOptions function at the command line.

For examples, see Configure Driver and Data Source. Otherwise, see Driver Installation for information about installing your driver. For configuring MySQL® or PostgreSQL native interfaces, see MySQL Native Interface or PostgreSQL Native Interface.

If your data source is already defined, then you are ready to connect to your database. If you do not define a data source, you can connect to your database using a DSN-less connection string with the odbc function. (DSN is a data source name.) For details, see Connect 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

Usage

Database Explorer app

  • 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

  • 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.

Several options enable you to connect to your database at the command line. Use this table to choose your best command line connection option.

Command Line Connection Option

Usage

ODBC connection

Connect to your database with maximum performance.

DSN-less connection

Connect to your database by using a connection string. For details, see the odbc function.

Native interface connection

Connect to MySQL and PostgreSQL databases. For PostgreSQL databases, you can connect without the installation of a driver. For details, see MySQL Native Interface and PostgreSQL Native Interface.

JDBC connection

Achieve maximum platform independence.

SQLite connection

Import data without installing a database or driver. For details, see Interact with Data in SQLite Database Using MATLAB Interface to SQLite.

You can create multiple connections at a time to the same database or different databases. 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