Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

close

Close database and driver resource utilizer

resultset will be removed in a future release.

Syntax

Description

example

close(object) closes the database and driver resource utilizer object to free up database and driver resources.

Examples

collapse all

Using the native ODBC interface, connect to the database with the ODBC data source name dbtoolboxdemo, the user name admin, and the password admin.

conn = database.ODBCConnection('dbtoolboxdemo','admin','admin');

Close the database connection conn.

close(conn)

Create a SQLite connection conn using the MATLAB® interface to SQLite and the existing database file tutorial.db, which resides in the current working folder.

dbfile = fullfile(pwd,'tutorial.db');

conn = sqlite(dbfile);

Close the SQLite connection conn.

close(conn)

Using a JDBC driver, create a database connection conn to a Microsoft® SQL Server® database with Windows® authentication. Specify a blank user name and password. The code assumes that you are connecting to a database toy_store, a database server dbtb04, and port number 54317.

conn = database('toy_store','','','Vendor','Microsoft SQL Server', ...
    'Server','dbtb04','PortNumber',54317,'AuthType','Windows');

Create a DatabaseDatastore object dbds using the database connection conn and SQL query sqlquery. This SQL query retrieves all data from the table airlinesmall.

sqlquery = 'select * from airlinesmall';

dbds = databaseDatastore(conn,sqlquery);

Close the DatabaseDatastore object dbds.

close(dbds)

Using the native ODBC interface, connect to the database with the ODBC data source name dbtoolboxdemo, the user name admin, and the password admin.

conn = database.ODBCConnection('dbtoolboxdemo','admin','admin');

Select data from the table productTable that you access using the database.ODBCConnection object conn. Assign the returned cursor object to the variable curs.

sqlquery = 'select * from productTable';
curs = exec(conn,sqlquery);

After you finish working with the cursor object, close it.

close(curs)

Close the database connection conn.

close(conn)

Connect to the database with the ODBC data source name dbtoolboxdemo, the user name admin, and the password admin.

conn = database('dbtoolboxdemo','admin','admin');

Select data from the table productTable that you access using the database connection object conn. Assign the returned cursor object to the variable curs.

sqlquery = 'select * from productTable';
curs = exec(conn,sqlquery);

Construct a resultset object rset.

rset = resultset(curs);

Close the resultset object rset.

close(rset)

After you finish working with the cursor object, close it.

close(curs)

Close the database connection conn.

close(conn)

Related Examples

Input Arguments

collapse all

Database and driver resource utilizer, specified as one of these objects.

Object Argument NameObject NameObject DescriptionObject Creation Function

conn

Database connection object or native ODBC database connection object

A database connection object creates a connection between an installed database and MATLAB®. For details, see Connecting to a Database.

database

conn

SQLite connection object

A SQLite connection object creates a connection to a SQLite database file using the MATLAB interface to SQLite. For details, see Working with the MATLAB Interface to SQLite.

sqlite

dbds

DatabaseDatastore object

A DatabaseDatastore object creates a connection to a type of datastore for working with large data.

databaseDatastore

curs

Cursor object or native ODBC cursor object

A cursor object stores imported data.

exec

rset

Resultset object

A resultset object provides metadata about cursor objects.

resultset

Database connections, SQLite connections, DatabaseDatastore objects, cursors, and resultset objects remain open until you close them using the close function. Always close a cursor, DatabaseDatastore, database or SQLite connection, or resultset object when you finish using it. Close a cursor before closing the connection used for that cursor. Executing close with a DatabaseDatastore object releases the MATLAB resources associated with database connection and cursor objects.

    Note:   The MATLAB session closes open cursors, DatabaseDatastore objects, and connections when exiting. However, the database might not free up the cursors and connections.

Introduced before R2006a

Was this topic helpful?