Enabling dynamic SQL statement caching for ODBC function calls

To reduce the overhead for function calls, you can prepare a statement once and execute it repeatedly throughout the application.

About this task

Db2 servers cache prepared versions of dynamic SQL statements. This dynamic caching allows the Db2 server to reuse previously prepared statements.

Procedure

To take advantage of dynamic caching for ODBC function calls, take any of the following actions:

  • Use the same statement handle to execute identical SQL statements, and free this handle only when you no longer need to execute that statement repeatedly.
    For example, if your application routinely uses a set of 10 SQL statements, allocate 10 statement handles that are associated with each of those statements. Do not free these statement handles until you can no longer execute the statements that are associated with them.
    You can roll back and commit the transaction without affecting prepared statements. Your application can continue to prepare and execute the statements in a normal manner. The Db2 server determines if a prepare is actually needed.
  • Set the LITERALREPLACEMENT property to 1 so that Db2 can share a cache entry for dynamic statements that are identical except for the literal constants and also meet the other standard criteria for sharing a cached entry.
    This sharing of the dynamic cache entry might improve your application performance.