Compiling and running SQLJ programs

If your Java™ program has embedded SQLJ statements, you need to follow a special procedure to compile and run it.

If your Java program has embedded SQLJ statements, you need to follow a special procedure to compile and run it.

  1. Set up your server to use SQLJ.
  2. Use the SQLJ translator, sqlj, on your Java source code with embedded SQL to generate Java source code and associated profiles. There is one profile generated for each connection.

    For example, type in the following command:

         sqlj MyClass.sqlj
    where MyClass.sqlj is the name of your SQLJ file.

    In this example, the SQLJ translator generates a MyClass.java source code file and any associated profiles. The associated profiles are named MyClass_SJProfile0.ser, MyClass_SJProfile1.ser, MyClass_SJProfile2.ser, and so on.

    Note: The SQLJ translator automatically compiles the translated Java source code into a class file unless you explicitly turn off the compile option with the -compile=false clause.
  3. Use the SQLJ Profile Customizer tool, db2profc, to install DB2 SQLJ Customizers on generated profiles and create the DB2 packages on the local system.

    For example, type in the command:

         db2profc MyClass_SJProfile0.ser
    where MyClass_SJProfile0.ser is the name of the profile on which the DB2 SQLJ Customizer is run.
    Note: This step is optional but is recommended to increase runtime performance.
  4. Run the Java class file just like any other Java class file.

    For example, type in the command:

         java MyClass
    where MyClass is the name of your Java class file.