16.10.2015 Views

Getting Startedwith pureQuery

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

350<br />

<strong>Getting</strong> Started with <strong>pureQuery</strong><br />

D.4 The mechanics of static SQL with DB2<br />

When an application executes static SQL statements in DB2, it needs an alternate way of<br />

telling the server which statement it wants to execute. Since static SQL is already defined<br />

at the server, the application does not need to send an SQL string to the server at runtime,<br />

as it does for dynamic SQL. It only needs to identify to the server which pre-defined SQL<br />

statement to execute. DB2 uses sections and packages as identifiers to organize and<br />

manage the static SQL statements that have been defined. (higher level organizing units<br />

such as collections, or for DB2 for z/OS plans or DBRMs are out of the scope of this<br />

appendix.)<br />

A package is the basic organizing unit for SQL statements at the server. A package is a<br />

named and uniquely identifiable grouping of related SQL statements.<br />

A section is the building block of a package. Each section is associated with one SQL<br />

statement. A package usually has one or more sections identified by an integer number.<br />

DB2 uses sections to execute both dynamic and static SQL.<br />

Packages and sections are internally used by DB2 for execution of SQL statements in both<br />

dynamic and static mode. While in static mode these organizing units are explicitly created<br />

by the user at precompile and bind time, in dynamic mode they are used implicitly by DB2<br />

when it binds the dynamic SQL statements. When connecting to DB2 from a Java<br />

application, DB2 uses the implicit JDBC packages and sections to store the access plans<br />

for the dynamically executed SQL statements. Because execution is dynamic, the SQL<br />

string is provided by the application at runtime. The statement and its dynamically<br />

determined access plan are depicted outside the package because the package does not<br />

contain the definition of the statement or know the acces plan prior to execution time, as<br />

illustrated in Figure D.6.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!