User`s guide

7 Functions — Alphabetical List
7-204
close(res2)
close(conn)
Run SQL Script to Fetch Data in Batches
Run SQL commands from a file on a connected data source with automated batching.
Use this method to avoid Java heap memory issues when the SQL script returns a large
amount of data.
To get the file of SQL commands, navigate to \toolbox\database\dbdemos
\compare_sales.sql in your MATLAB root folder, or copy and paste the path into
your current working folder.
Create the connection object to the data source, dbtoolboxdemo.
conn = database('dbtoolboxdemo','','');
Alternatively, you can use the native ODBC interface for an ODBC connection. For
details, see database.
Turn on batching for fetch.
setdbprefs('FetchInBatches', 'yes')
Set appropriate batch size depending on the size of the resultset you expect to fetch. For
example, if you expect about a 100,000 rows in the output, a batch size of 10,000 is a good
starting point. The larger the FetchBatchSize value, the fewer trips between Java
and MATLAB, and the memory consumption is greater for each batch. There are several
factors that determine the optimal value for FetchBatchSize. These factors are some
examples:
Size per row being retrieved
Java heap memory value
Default fetch size of the driver
System architecture
Hence, the FetchBatchSize might vary from site to site. For details about estimating a
value for FetchBatchSize, see “Preference Settings for Large Data Import”.
setdbprefs('FetchBatchSize', '2')
Run the SQL script, compare_sales.sql.