Quantcast

Documentation Center

  • Trial Software
  • Product Updates

close

Close database connection, cursor, or resultset object

Syntax

Description

example

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

Examples

expand all

Close the Database Connection Object

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

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

Close the database connection conn.

close(conn);

Close the Cursor Object

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

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

Select data from 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);

Close the cursor object curs before closing the database connection.

close(curs);

Close the database connection conn.

close(conn);

Close the Resultset Object

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

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

Select data from 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);

Close the cursor object curs before closing the database connection.

close(curs);

Close the database connection conn.

close(conn);

Input Arguments

expand all

object — Database and driver resource utilizerdatabase connection object | cursor object | resultset object

Database and driver resource utilizer, specified as a database connection object created using database, a cursor object created using exec, or a resultset object created using resultset. The following table describes the allowable objects for close.

ObjectDescription

conn

Database connection object or native ODBC database connection object

curs

Cursor object or native ODBC cursor object

rset

Resultset object

Database connections, cursors, and resultset objects remain open until you close them using the close function. Always close a cursor, connection, or resultset object when you finish using it. Close a cursor before closing the connection used for that cursor.

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

See Also

| | |

Was this topic helpful?