Home

 

Developing SQLJ applications

SQLJ enables you to embed SQL statements into Java programs. SQLJ is an ANSI standard developed by a consortium of leading providers of database and application server software.

The SQLJ translator translates an SQLJ source file into a standard Java source file plus an SQLJ serialized profile that encapsulates information about static SQL in the SQLJ source. The translator converts SQLJ clauses to standard Java statements by replacing the embedded SQL statements with calls to the SQLJ runtime library. An SQLJ customization script binds the SQLJ profile to the database, producing one or more database packages. The Java file is compiled and run (with the packages) on the database. The SQLJ runtime environment consists of an SQLJ runtime library that is implemented in pure Java. The SQLJ runtime library calls the JDBC driver for the target database.

SQLJ provides better performance by using static SQL. SQLJ generally requires fewer lines of code than JDBC to perform the same tasks. The SQLJ translator checks the syntax of SQL statements during translation. SQLJ uses database connections to type-check static SQL code. With SQLJ, you can embed Java variables in SQL statements. SQLJ provides strong typing of query output and return parameters and allows type-checking on calls. SQLJ provides static package-level security with compile-time encapsulation of database authorization.

Using the SQLJ wizard shipped with RAD v7.5, you can do the following actions:

Name an SQLJ file and specify its package and source folder.

Specify advanced project properties, such as additional JAR files, to add to the project classpath, translation options, and whether to use long package names.

Select an existing SQL SELECT statement, or construct and test a new one.

Specify information for connecting to the database at run time.

In this section, we will create an SQLJ application to retrieve the customer and the associated account information.

ibm.com/redbooks