IBM Books

Building Applications for UNIX** Environments


SQLJ Programs

Applications

App demonstrates an SQLJ application that accesses a DB2 database.

Command Line. To build and run this application by commands entered at the command line:

  1. Translate App.sqlj with this command:

    sqlj App.sqlj

    This will produce the files App.java and App_SJProfile0.ser.

  2. Compile App.java with this command:
    javac App.java
    

    This will produce the files: App.class, App_Cursor1.class, App_Cursor2.class and App_SJProfileKeys.class.

  3. Customize the generated profile and create the package App in the sample database with this command:
    db2profc -url=jdbc:db2:sample prepoptions="package using App" App_SJProfile0
    

  4. Run the application with this command:
    java App
    

makefile. To build this application with the makefile, and then run it:

  1. Ensure your environment includes a compatible make utility as specified in the section "The Java makefile".

  2. Build the application with this command:
    make App
    

  3. Run the application with this command:
    java App
    

Applets

Applt demonstrates an SQLJ applet that accesses a DB2 database.

Command Line. To build and run this applet by commands entered at the command line:

  1. Ensure that a web server is installed on your DB2 machine (server or client).

  2. Modify the Applt.html file according to the instructions there.

  3. Start the JDBC applet server on the TCP/IP port specified in Applt.html; for example, if in Applt.html, you specified:

    param name=port value='6789'

    then you would enter:

    db2jstrt 6789
    

  4. Translate Applt.sqlj with this command:

    sqlj Applt.sqlj

    This will produce the files: Applt.java and Applt_SJProfile0.ser.

  5. Compile Applt.java with this command:
    javac Applt.java
    

    This will produce the files: Applt.class, Applt_Cursor1.class, Applt_Cursor2.class and Applt_SJProfileKeys.class.

  6. Customize the generated profile and create the package Applt in the sample database with this command:
    db2profc -url=jdbc:db2:sample -prepoptions="package using Applt" Applt_SJProfile0
    

  7. Ensure that your working directory is accessible by your web browser. If it is not, copy the following files into a directory that is accessible:
    Applt.html                              Applt.class,
    Applt_Cursor1.class,                    Applt_Cursor2.class,
    Applt_SJProfileKeys.class,              Applt_SJProfile0.ser
    

  8. Copy the files sqllib/java/db2java.zip and sqllib/java/runtime.zip into the same directory as your other Applt files.

  9. On your client machine, start your web browser (which must support JDK 1.1) and load Applt.html.

As an Alternative to steps (1), (7) and (9), you can use the applet viewer that comes with the Java Development Kit by entering the following command in the working directory of your client machine:

appletviewer Applt.html

makefile. To build this applet with the makefile, and then run it:

  1. Ensure your environment includes a compatible make utility as specified in the section "The Java makefile".

  2. Ensure that a web server is installed on your DB2 machine (server or client).

  3. Modify the Applt.html file according to the instructions there.

  4. Start the JDBC applet server on the TCP/IP port specified in Applt.html. For example, if in Applt.html, you specified:

    param name=port value='6789'

    then you would enter:

    db2jstrt 6789
    

  5. Build the applet with this command:
    make Applt
    

  6. Ensure that your working directory is accessible by your web browser. If it is not, copy the following files into a directory that is accessible:
    Applt.html,                             Applt.class,
    Applt_Cursor1.class,                    Applt_Cursor2.class,
    Applt_SJProfileKeys.class,              Applt_SJProfile0.ser
    

  7. Copy the files sqllib/java/db2java.zip and sqllib/java/runtime.zip into the same directory as your other Applt files.

  8. On your client machine, start your web browser (which must support JDK 1.1) and load Applt.html.

As an Alternative to steps (2), (6) and (8), you can use the applet viewer that comes with the Java Development Kit by entering the following command in the working directory of your client machine:

appletviewer Applt.html

Stored Procedures

Stp demonstrates an SQLJ stored procedure that accesses a DB2 database.

Command Line. To build and run this stored procedure by commands entered at the command line:

  1. Translate Stp.sqlj with this command:

    sqlj Stp.sqlj

    This will produce the files Stp.java and Stp_SJProfile0.ser.

  2. Compile Stp.java with this command:

    javac Stp.java

    This will produce the files: Stp.class, Stpsrv.class, Stp_Cursor1.class, Stp_Cursor2.class and Stp_SJProfileKeys.class.

  3. Customize the generated profile and create the package Stp in the sample database with this command:
    db2profc -url=jdbc:db2:sample -prepoptions="package using Stp" Stp_SJProfile0
    

  4. Copy these files to the sqllib/function directory: Stpsrv.class, Stp_Cursor1.class, Stp_Cursor2.class, Stp_SJProfileKeys.class and Stp_SJProfile0.ser.

  5. Run the stored procedure with this command:
    java Stp
    

makefile. To build this stored procedure with the makefile, and then run it:

  1. Ensure your environment includes a compatible make utility as specified in the section "The Java makefile".

  2. Build the stored procedure with this command:
    make Stp
    

  3. Run the stored procedure with this command:
    java Stp
    

User-Defined Functions

The sqllib/samples/java directory includes a UDF application consisting of three SQLJ programs:

CatUdf.

Command Line. To build and run this SQLJ program by commands entered at the command line:

  1. Translate CatUdf.sqlj with this command:

    sqlj CatUdf.sqlj

    This will produce the files CatUdf.java and CatUdf_SJProfile0.ser.

  2. Compile CatUdf.java with this command:

    javac CatUdf.java

    This will produce the files CatUdf.class and CatUdf_SJProfileKeys.class.

  3. Customize the generated profile and create the package CatUdf in the sample database with this command:
    db2profc -url=jdbc:db2:sample -prepoptions="package using CatUdf" CatUdf_SJProfile0
    

  4. Run CatUdf with this command:
    java CatUdf
    

  5. Next, run the Udf program.

makefile. To build and run this SQLJ program with the makefile:

  1. Ensure your environment includes a compatible make utility as specified in the section "The Java makefile".

  2. Build and run CatUdf with this command:
    make CatUdf
    

  3. Next, run the Udf program.

Udf.

Command Line. To build and run this SQLJ program by commands entered at the command line:

  1. Translate Udf.sqlj with this command:

    sqlj Udf.sqlj

    This will produce the files Udf.java and Udf_SJProfile0.ser.

  2. Compile Udf.java with this command:

    javac Udf.java

    This will produce the files: Udf.class, Udf_Cursor1.class, Udf_Cursor2.class, Udf_Cursor4.class, Udf_Cursor5.class, Udf_SJProfileKeys.class and Udfsrv.class.
    Note:There is no file Udf_Cursor3.class.

  3. Customize the generated profile and create the package Udf in the sample database with this command:
    db2profc -url=jdbc:db2:sample -prepoptions="package using Udf" Udf_SJProfile0
    

  4. Copy the Udfsrv.class file into sqllib/function.

  5. Run Udf with this command:
    java Udf
    

  6. Next, run the DropUdf program.

makefile. To build this SQLJ program with the makefile, and then run it:

  1. Ensure your environment includes a compatible make utility as specified in the section "The Java makefile".

  2. Build Udf with this command:
    make Udf
    

  3. Run Udf with this command:
    java Udf
    

  4. Next, run the DropUdf program.

DropUdf.

Command Line. To build and run this SQLJ program by commands entered at the command line:

  1. Translate DropUdf.sqlj with this command:

    sqlj DropUdf.sqlj

    This will produce the files DropUdf.java and DropUdf_SJProfile0.ser.

  2. Compile DropUdf.java with this command:

    javac DropUdf.java

    This will produce the files: DropUdf.class and DropUdf_SJProfileKeys.class.

  3. Customize the generated profile and create the package DropUdf in the sample database with this command:
    db2profc -url=jdbc:db2:sample -prepoptions="package using DropUdf" 
                   DropUdf_SJProfile0
    

  4. Run DropUdf with this command:
    java DropUdf
    

makefile. To build this SQLJ program with the makefile, and then run it:

  1. Ensure your environment includes a compatible make utility as specified in the section "The Java makefile".

  2. Build DropUdf with this command:
    make DropUdf
    

  3. Run DropUdf with this command:
    java DropUdf
    


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]

[ DB2 List of Books | Search the DB2 Books ]