Execute prepared statements

If a SQL IBM® i Access ODBC statement is used more than once, it is best to have the statement prepared and then executed.

When a statement is prepared, variable information can be passed as parameter markers, which are denoted by question marks (?). When the statement is executed, the parameter markers are replaced with the real variable information.

Preparing the statement is performed at the server. The SQL statements are compiled and the access plans are built. This allows the statements to be executed much more efficiently. When compared to using dynamic SQL to execute the statements, the result is much closer to static SQL. Extended Dynamic preserves prepared statements across job sessions. This allows prepared statements with parameter markers to be executed multiple times within the job session even without Extended Dynamic ON. When the database server prepares the statements, it saves some of them in a special IBM i object called a package (*SQLPKG). This approach is called Extended Dynamic SQL. Packages are created automatically by the driver; an option is provided to turn off Package Support. See the topic below on the performance architecture of the driver for more information.