Compile and run SQLJ programs

If you 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.
Related concepts
Structured Query Language for Java profiles
The structured query language for Java (SQLJ) translator (sqlj)
Precompile SQL statements in a profile using the DB2 SQLJ profile customizer, db2profc
Print the contents of DB2 SQLJ profiles (db2profp and profp)
SQLJ profile auditor installer (profdb)
Embed SQL statements in your Java application
Embed SQL statements in your Java application
Related tasks
Convert a serialized profile instance to Java class format using the SQLJ profile conversion tool (profconv)