SQL/MX Programming Manual for Java
Introduction
HP NonStop SQL/MX Programming Manual for Java—523726-003
1-5
SQLJ and JDBC Interoperability
Development-Time Validation
The SQLJ translator provides online checking of the syntactic and semantic
correctness at the time of development, thus enabling you to validate the SQL
statements in an SQLJ program based on an actual database.
At the time of development, the SQLJ translator and the SQLJ customizer:
•
Verify the names, scope, and data types of the host variables in each SQL
statement
•
Check the syntax and semantics of the entire SQL statement
•
Verify that the referenced database objects exist
In contrast, JDBC passes values to and from SQL tables without the benefit of online
checking at the time of development. Therefore, you discover syntactical or semantic
errors in SQL statements only when you run the JDBC program.
JDBC Expertise Not Required
The implementation of SQLJ must support a specific version of JDBC to be compliant
with the SQLJ standard. However, as an application developer, you need not know the
JDBC application programming interfaces (APIs) to write an SQLJ program. For JDBC
requirements, see Software Requirements on page 2-1.
For more information about JDBC, see the JDBC Driver for SQL/MX Programmer’s
Reference.
SQLJ and JDBC Interoperability
In an SQLJ program, you typically use embedded SQL statements in SQLJ clauses for
static SQL and use JDBC methods for dynamic SQL. SQLJ provides interoperability
between SQLJ clauses and JDBC methods through the use of connection contexts
and result set iterators.
SQLJ programs use a connection context to associate SQL statements with a
database, and the connection context involves a JDBC connection. You can execute
both static and dynamic SQL statements in the same session and transaction context.
For more information about connecting to a database, see Code Initialization on
page 3-4 and Connection Contexts on page 3-8.
An SQLJ iterator is similar to a JDBC result set, and one can be cast to the other. You
can create an iterator from a JDBC result set with the SQLJ CAST statement (not to be
confused with the SQL CAST function). And, you can apply the getResultSet()
method to an iterator to return the JDBC result set. For more information, see
Converting Between SQLJ Iterators and JDBC Result Sets on page 3-56.