User`s guide

Importing Data Using the fetch Function
6-49
Note: You can pass conn as an input argument to fetch when using an JDBC/ODBC
bridge or a JDBC interface. For the native ODBC interface, use curs as the input
argument.
To create a database connection using the native ODBC interface, use
database.ODBCConnection.
conn = database.ODBCConnection(...)
fetch then runs when you pass a native ODBC cursor object, curs, to retrieve as an
argument.
curs = exec(conn,sqlquery)
curs = fetch(curs)
When fetch returns a cursor object, you can run many other functions, such as get and
rows. To import data into the MATLAB workspace without metadata, use fetch with a
database connection object as the input argument.
Using fetch with a Cursor Object
fetch returns data stored in a MATLAB cell array, table, dataset array, structure, or
numeric matrix. You can specify the data output format by using setdbprefs.
When working with a JDBC or JDBC/ODBC bridge connection established using
database, running fetch on the cursor object returns a new object of type cursor
that points to the same underlying Java objects as the input cursor. It is therefore
best practice to overwrite the input cursor object. This practice results in only one
open cursor object, which consumes less memory than multiple open cursor objects.
curs = fetch(curs)
After this, you simply need to close this one object. Creating a different variable for
the output cursor object will unnecessarily create two objects pointing to the same
underlying Java statement and result set objects.
With a native ODBC connection established using database.ODBCConnection,
running fetch on the cursor object updates the input cursor object itself. Depending
on whether or not you provide an output argument, the same object gets copied over
to the output. Thus, there is always only one cursor object created in memory for any
of the following usages:
curs = fetch(curs)