IBM Informix Embedded Documentation Notes

=================================

DOCUMENTATION NOTES

FOR

IBM Informix Embedded SQLJ 1.01.JC2

DATE: December, 2001

=================================

1. I. OVERVIEW OF DOCUMENTATION NOTES
2. II. NEW MATERIAL
3. III. CORRECTIONS

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

# I. OVERVIEW OF DOCUMENTATION NOTES

The purpose of these documentation notes is to make you aware of features not described in the "IBM Informix Embedded SQLJ User's Guide" or features that have changed since its publication.

# II. NEW MATERIAL

The following sections contain material not included in the "IBM Informix Embedded SQLJ User's Guide."

## A. INTEROPERATION OF JDBC RESULT SETS AND SQLJ ITERATORS

JDBC ResultsSet objects and SQLJ iterator objects are interoperable.

To obtain the JDBC ResultSet of a corresponding iterator, use the getResultSet() method.

To convert a JDBC ResultSet "rs" into a SQLJ iterator "iter," use the following syntax:

    #sql iter = { CAST :rs };

The argument of the cast must always implement java.sql.ResultSet, and like the SELECT statement, the CAST statement must appear to the right of the iterator name.

The following example is from the sample program Demo05.sqlj, which is located in the /demo/sqlj directory.

            String qry = "SELECT * from customer";

            try

            {

                rs  = stmt.executeQuery(qry);

            }

            catch (Exception e)

            {

                System.out.println("Failed to execute query");

            }

            // Declare Iterator of type CustRec

            CustRec cust_rec;

            // Convert JDBC ResultSet into SQLJ Iterator

            #sql cust_rec = { CAST :rs };

            int row_cnt = 0;

            while ( cust_rec.next() )

                {

                ......

                }

## B. INTEROPERATION OF JDBC CONNECTIONS AND SQLJ CONNECTION-CONTEXTS

JDBC Connection objects and SQLJ connection-context objects are interoperable.

To obtain the underlying JDBC Connection object for an SQLJ connection-context object, use the getConnection() method.

To create a SQLJ connection-context object, specify either the default connection context (DefaultContext) or a typed connection-context class.

The following example is from the sample program Demo06.sqlj, which is located in the /demo/sqlj directory.

            Connection conn = DriverManager.getConnection (DBURL, UID, PWD);

            #sql context ItemsCtx;

            ItemsCtx  i_ctx = null;

            i_ctx = new ItemsCtx(conn);

            try

                {

                    ctx = new DefaultContext(conn);

                }

                catch (SQLException e)

                {

                    System.out.println("Error:could not get a default context");

                    System.err.println(e) ;

                    System.exit(1);

                }

                DefaultContext.setDefaultContext(ctx);

## C. NEW SAMPLE PROGRAMS

The following sample programs have been added to the /demo/sqlj directory:

- MultiConnect.sqlj, which demonstrates how to use multiple connection contexts
- Demo07.sqlj, which demonstrates how to use the execution context

The README file in the /demo/sqlj directory explains how to compile and run the programs.

# III. CORRECTIONS

The following table contains corrections to ifxsqlj command line options listed in Chapter 5, "Processing Embedded SQLJ Source Code."

Option | Description
--- | ---
-help | Displays the names of commonly used ifxsqlj options.
-help-long | Displays the names, descriptions, and current settings of ifxsqlj options. The list displays: the name of the option. the type of the option (for example, if it is Boolean) or a selection of allowed values. the current value. a description of the option. whether the property is at its default or was set by either a property file or the command line. No translation or compilation is performed when you specify the -help option.
-linemap | Enables the mapping of line numbers between the .sqlj file and the corresponding .class file. The -linemap option allows you to trace runtime errors back to the .sqlj source code file. The SQLJ Translator replaces the line numbers and filename of the generated .java file with the corresponding line numbers and filename of the .sqlj file. The name of the .sqlj file must match the name of the class it implements. For example, the class name in foo.sqlj must be foo(). Errors are reported as follows: Translation errors are reported in terms of the line numbers of the .sqlj file. If compilation is invoked from SQLJ, compilation errors are reported in terms of the line numbers of the .sqlj file. If compilation is not invoked from SQLJ, compilation errors are reported in terms of the line numbers of the generated .java file.
-password | Specifies a password for the user name set with the -user option. If you specify the -user option, but not the -password option, the translator prompts you for the password. You can specify the user and password together as follows:
    -user=userid/password
You can specify a password for a particular connection context as follows:
    password@CtxClass2=xxxx
If you are using multiple connection contexts, the setting for -password for the default connection context also applies to any connection context that does not have a specific setting.