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.
- Set up your server to use SQLJ.
- 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:
where MyClass.sqlj is the name of your SQLJ file.sqlj MyClass.sqljIn 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. - 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:
where MyClass_SJProfile0.ser is the name of the profile on which the DB2 SQLJ Customizer is run.db2profc MyClass_SJProfile0.serNote: This step is optional but is recommended to increase runtime performance. - Run the Java class file just like any other Java class
file.
For example, type in the command:
where MyClass is the name of your Java class file.java MyClass
Parent topic: Accessing databases using DB2 SQLJ support
Related concepts: