Executing SQL Statements

There are two main functions in DB2 ODBC for executing SQL statements: SQLExecDirect() and SQLExecute(). The SQLExecDirect() function prepares and executes a SQL statement similar to the SQL EXECUTE IMMEDIATE embedded dynamic SQL statement.

SQLRETURN SQLExecDirect (SQLHSTMT     StatementHandle, 
                         SQLCHAR     *Statement,
                         SQLINTEGER   StatementLength);

The SQLExecute() function requires that the statement be prepared using SQLPrepare() first. Once the statement has been prepared it can be executed many times, saving CPU resources.

SQLRETURN SQLPrepare    (SQLHSTMT     StatementHandle, 
                         SQLCHAR     *Statement,
                         SQLINTEGER   StatementLength);
SQLRETURN SQLExecute    (SQLHSTMT     StatementHandle);

Because the statement is dynamic, a program can put literal ...

Get DB2® Universal Database™ for OS/390™ v7.1 Application Certification Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.