SQLJ is a standard for using Java and SQL together. It has been developed by a consortium of companies comprising IBM, Informix, Microsoft, Sun, Sybase and Oracle. SQLJ consists of three parts, each addressing different aspects of this interaction:
· SQLJ Part 0: Object Language Bindings (SQL/OLB): Embedded static SQL within Java code.
· SQLJ Part 1: SQL Routines using the Java Language: Java methods as SQL stored procedures on the database server.
· SQLJ Part 2: SQL Types using the Java Programming Language: Java classes as user-defined SQL types
SQLJ Part 0 (SQL / OLB) is by far the most widespread part of SQLJ and only this part has been adopted by SAP. It is standardized by the ISO/IEC standard 9075-10. Here, we simply refer to SQL/OLB as SQLJ.
SQLJ defines a syntax for directly embedding static SQL statements (SQLJ statements) into Java source code. The Java compiler cannot recognize the embedded SQL statements. Instead, a special source file type with the extension ".sqlj" indicates that the source file is an SQLJ source file. In a pre-processor step, the SQLJ translator translates the SQLJ source files to intermediate Java source files in which the SQLJ statements are replaced by calls to the SQLJ runtime. The intermediate Java file is translatable with the Java compiler. The Programmer deals only with the SQLJ source file.
The SQLJ Translator
In a pre-processor step, the SQLJ translator translates the SQLJ source file to an intermediate Java source file in which the SQLJ statements are replaced by calls to the SQLJ runtime. The intermediate Java source file is translated by the Java compiler.
An SQLJ implementation comprises the following:
· An SQLJ-translator, which translates special SQLJ-source code (denoted by the file extension “.sqlj”) to Java-source code. In this Java source code, the embedded SQL statements are replaced by calls to a SQLJ runtime.
· The SQLJ-runtime, which is capable of executing these calls against the database – typically using JDBC.
The ISO/IEC standard only defines a grammar to embed SQL statements in Java and to exchange data with the database. However, it does not define the subset of SQL to be supported.
Open SQL/SQLJ is an implementation of SQLJ provided by SAP, which allows platform independent SQLJ to be written. Open SQL/SQLJ is part of the topmost layer of the Open SQL for Java framework. For example, you cannot use it with a Native SQL connection.
The Open SQL/SQLJ translator performs checks on the embedded SQL statements. The syntax is always checked for conformance with the Open SQL grammar. It is not possible to process database specific SQL with the Open SQL/SQLJ translator. Schema checking is performed against the offline catalog provided by Java Dictionary. The Open SQL/SQLJ translator is transparently integrated into The SAP NetWeaver Developer Studio.
Open SQL/SQLJ has a number of advantages over Open SQL/JDBC:
Therefore, Open SQL/SQLJ is the best choice for using static SQL; for dynamic SQL, Open SQL/JDBC should be used.
For more information about the Open SQL/SQLJ features, see:
· Creating and Editing SQLJ Sources
· Host Variables and Host Expressions
· Transactions in Open SQL/SQLJ
See also:
Open SQL/SQLJ does not support the following features:
· SQL block clause
· Stored procedures and stored functions
· Positional update or delete operations