SQL/MX Programming Manual for Java

Introduction
HP NonStop SQL/MX Programming Manual for Java523726-003
1-3
SQLJ Compared With Embedded SQL in C or
COBOL
incompatible types in a C or COBOL program but are compatible types in an SQLJ
program because Java defines those type conventions.
Java handles a greater variety of conversions between SQL column data types and
host variables than does C or COBOL. For example, SQLJ converts a fetched string
value to a host variable typed as integer, as long as the string represents a valid
integer. For more information about data type mappings, see Data Type Support on
page 3-32.
Easier Localization and Internationalization
SQLJ programs are much easier to localize and internationalize than embedded SQL
programs in C or COBOL because Java uses Unicode internally and supports many
character set encodings. Unlike embedded SQL programs in C or COBOL, you do not
prefix host variable declarations with the type of the character set in SQLJ programs.
For more information, see Character Sets on page 3-40, Character String Literals on
page 3-45, and -encoding on page 5-22.
Null Values Instead of NULL Indicators
The null value represents the SQL NULL state. The Java null value provides an
alternative to the NULL indicators used in a C or COBOL application. The Java
wrapper classes for Java primitive data types can assume the null value. For an
example, see Null Values on page 3-29.
Robust Exception Handling
SQLJ provides more robust exception handling because it integrates SQL error
handling with Java exception handling in contrast to the SQL-92 error model in C and
COBOL applications.
In an embedded SQL program in C or COBOL, you are responsible for checking
SQLSTATE or SQLCODE after the execution of each SQL statement. This process of
exception handling places the checking of errors in the main path of code execution.
For example, in a C program, you would handle exceptions as follows:
EXEC SQL INSERT INTO samdbcat.persnl.employee...
if (SQLCODE != 0) {
/* handle error */
}
In a Java program, you can place error handling code outside the main code path. For
more information, see Handling Exception Conditions on page 3-60.
For more information about embedded SQL in C and COBOL programs, see the
SQL/MX Programming Manual for C and COBOL.