Use of Java to execute static and dynamic SQL

Db2 for z/OS® supports SQLJ and JDBC. In general, Java™ applications use SQLJ for static SQL, JDBC for dynamic SQL, and PureQuery for both static and dynamic SQL.

By using the Java programming language you gain the following key advantages:

  • You can write an application on any Java-enabled platform and run it on any platform to which the Java Development Kit (JDK) is ported.
  • You can develop an application once and run it anywhere, which offers the following potential benefits:
    • Reduced development costs
    • Reduced maintenance costs
    • Reduced systems managements costs
    • Flexibility in supporting diverse hardware and software configurations

The following table shows some of the major differences between SQLJ and JDBC.

Table 1. Comparison of SQLJ and JDBC
SQLJ characteristics JDBC characteristics
SQLJ follows the static SQL model and offers performance advantages over JDBC. JDBC follows the dynamic SQL model.
SQLJ source programs are smaller than equivalent JDBC programs because SQLJ automatically generates certain code that developers must include in JDBC programs. JDBC source programs are larger than equivalent SQLJ programs because certain code that the developer must include in JDBC programs is generated automatically by SQLJ.
SQLJ checks data-types during the program preparation process and enforces strong typing between table columns and Java host expressions. JDBC passes values to and from SQL tables without checking data types at compile time.
In SQLJ programs, you can embed Java host expressions in SQL statements. JDBC requires a separate statement for each bind variable and specifies the binding by position number.
SQLJ provides the advantages of static SQL authorization checking. With SQLJ, the authorization ID under which SQL statements run is the plan or package owner. Db2 checks the table privileges at bind time. Because JDBC uses dynamic SQL, the authorization ID under which SQL statements run is not known until run time, so no authorization checking of table privileges can occur until run time.