SQL/MX Programming Manual for Java
Introduction
HP NonStop SQL/MX Programming Manual for Java—523726-003
1-2
SQLJ Compared With Embedded SQL in C or
COBOL
•
Strong data typing of queries
•
Online checking of syntactic and semantic correctness of SQL statements at
development time rather than at run time
•
Portability of binary code across different vendors’ databases
•
Customization of an SQLJ program for optimal performance on an SQL/MX
database
SQLJ Compared With Embedded SQL in C or COBOL
SQLJ offers the following benefits as compared with embedded SQL statements in a C
or COBOL program.
Binary Portability
SQLJ applications have binary portability among different database systems. As a
result, you can run the same application against any database server without:
•
Modifying the original source code
•
Retranslating the source code by using an implementation-specific SQLJ translator
•
Recompiling the translated source code
Embedded SQL applications in C or COBOL have source-code portability. You can
compile a program on different platforms without changing the source code (that is, if
you do not use platform-specific extensions). Embedded SQL applications in C or
COBOL do not have binary portability because the format of the executable, or binary,
file is specific to the operating system on which the program is compiled. Because the
executable files are not portable across different platforms, you must recompile an
embedded SQL application in C or COBOL on each platform.
In contrast, SQLJ applications have both source-code portability of the source file
containing the embedded SQL (the .sqlj file) and binary portability of the Java
classes and profiles generated by the SQLJ translator. (For information about the
SQLJ translator, see Section 5, Processing SQLJ Programs.) The SQLJ translator
invokes a Java compiler that compiles the Java source file into a class file that contains
Java bytecode. Java bytecode is an instruction set that targets a virtual platform called
the Java virtual machine (JVM). A JVM on any platform can interpret Java bytecode,
so you can translate and compile an SQLJ application once and run it on any platform
that supports the JVM.
Better Integration of Java and SQL Data Types
SQLJ programs provide stronger data type enforcement than embedded SQL
programs in C or COBOL, whose host variables must follow type compatibility rules
based on SQL rules. In an SQLJ program, host variables must follow type compatibility
rules based on Java rules. The type conventions in Java are more flexible than those
in SQL. For example, character string and numeric data types are generally