Introduction to HCL Informix embedded SQLJ

This chapter explains what you can do with Informix® Embedded SQLJ and provides an overview of how embedded SQLJ works.

What is embedded SQLJ?

Informix Embedded SQLJ enables you to embed SQL statements in your Java™ programs. Informix Embedded SQLJ consists of:
  • The SQLJ translator, which translates SQLJ code into Java code
  • A set of Java classes that provide runtime support for SQLJ programs

Informix Embedded SQLJ includes the standard SQLJ implementation, as defined by the SQLJ consortium, plus specific Informix extensions. The rest of this manual refers to Informix Embedded SQLJ as Embedded SQLJ. The standard SQLJ implementation is referred to as traditional Embedded SQLJ.

How does embedded SQLJ work?

When you use Embedded SQLJ, you embed SQL statements in your Java source code. You use the SQLJ translator to convert the embedded SQL statements to Java source code with calls to JDBC. JDBC is the JavaSoft specification of a standard application programming interface (API) that allows Java programs to access database management systems.

Finally, you use the Java compiler to compile your translated Java program into an executable Java .class file, as shown in Translation and Compilation of an Embedded SQLJ Program.
Figure 1: Translation and Compilation of an Embedded SQLJ Program

The image shows that a SQLJ translator is used to change Java source code with embedded SQL into Java source code with calls to JDBC, and then a Java compiler is used to change the Java source code with calls to JDBC into Java byte codes with calls to JDBC.
When you run your program, it uses the Informix JDBC Driver to connect to the Informix database, as shown in Runtime Architecture for Embedded SQLJ Programs.
Figure 2: Runtime Architecture for Embedded SQLJ Programs

The image shows that the database sends results sets for SELECT statements to the JDBC Driver, which then sends the results to a Java executable, which then sends a call back to the JDBC driver, which then sends queries and other statements back to the database.

See the Informix JDBC Driver Programmer's Guide for information about using the Informix JDBC Driver.

Embedded SQLJ versus JDBC

Embedded SQLJ does not support dynamic SQL; you must use the JDBC API if you want to use dynamic SQL. Your Embedded SQLJ program can call the JDBC API to perform a dynamic operation (the SQLJ connection-context object that you use to connect an Embedded SQLJ program to the database contains a JDBC Connection object that you can use to create JDBC statement objects).

If you are using static SQL, Embedded SQLJ provides the following advantages:
  • Default connection context. You only need to set the default connection context once within a program; then every subsequent Embedded SQLJ statement uses this connection context unless you specify otherwise.
  • Reduced statement complexity. For example, you do not need to explicitly bind each variable; Embedded SQLJ performs binding for you. Generally, this feature allows you to create smaller programs than with the JDBC API.
  • Compile-time syntax and semantics checking. The Embedded SQLJ translator checks the syntax of SQL statements.
  • Compile-time type checking. The Embedded SQLJ translator and the Java compiler check that the Java data types of arguments are compatible with the SQL data types of the SQL operation.
  • Compile-time schema checking. You can connect to a sample database schema during translation to check that your program uses valid SQL statements for the tables, views, columns, stored procedures, and so on in your sample.