SQLJ.DB2_REPLACE_JAR stored procedure

SQLJ.DB2_REPLACE_JAR replaces an existing JAR file in the local DB2® catalog or in a remote DB2 catalog.

To replace a JAR file at a remote location, you need to execute a CONNECT statement to connect to that location before you call SQLJ.DB2_REPLACE_JAR.

SQLJ.DB2_REPLACE_JAR authorization

Privilege set: If the CALL statement is embedded in an application program, the privilege set consists of the privileges that are held by the owner of the plan or package. If the statement is dynamically prepared, the privilege set consists of the privileges that are held by the authorization IDs of the process.

For calling SQLJ.DB2_REPLACE_JAR, the privilege set must include at least one of the following items:
  • EXECUTE privilege on SQLJ.DB2_REPLACE_JAR
  • Ownership of SQLJ.DB2_REPLACE_JAR
  • SYSADM authority
The privilege set must also include the authority to replace a JAR, which consists of at least one of the following items:
  • Ownership of the JAR
  • ALTERIN privilege on the schema of the JAR

    The authorization ID that matches the schema name implicitly has the ALTERIN privilege on the schema.

  • SYSADM or SYSCTRL authority

SQLJ.DB2_REPLACE_JAR syntax

>>-CALL--SQLJ.DB2_REPLACE_JAR--(--JAR-locator,--JAR-name--)----><

SQLJ.DB2_REPLACE_JAR parameters

JAR-locator
A BLOB locator input parameter that points to the JAR file that is to be replaced in the DB2 catalog.
JAR-name
A VARCHAR(257) input parameter that contains the DB2 name of the JAR, in the form schema.JAR-id or JAR-id. JAR-name is the name that you use when you refer to the JAR in SQL statements. If you omit schema, DB2 uses the SQL authorization ID that is in the CURRENT SCHEMA special register.

SQLJ.DB2_REPLACE_JAR example

Suppose that you want to replace a previously installed JAR file that is named DB2INST3.BUILDPLAN with the JAR file that is in path /u/db2inst3/apps/BUILDPLAN2/BUILDPLAN.jar. The following Java program replaces the JAR file.

import java.sql.*; // JDBC classes
import java.io.IOException;
import java.io.File;
import java.io.FileInputStream;
class SimpleInstallJar
{
  public static void main (String argv[])
  {
    String url = "jdbc:db2://sysmvs1.stl.ibm.com:5021";
    String jarname = "DB2INST3.BUILDPLAN";
    String jarfile = 
      "/u/db2inst3/apps/BUILDPLAN2/BUILDPLAN.jar";
    try
    {
      Class.forName ("com.ibm.db2.jcc.DB2Driver").newInstance ();
      Connection con = 
        DriverManager.getConnection(url, "MYID", "MYPW");
      File aFile = new File(jarfile);
      FileInputStream inputStream = new FileInputStream(aFile);
      CallableStatement stmt;
      String sql = "Call SQLJ.DB2_REPLACE_JAR(?, ?)";
      stmt = con.prepareCall(sql);
      stmt.setBinaryStream(1, inputStream, (int)aFile.length());
      stmt.setString(2, jarname);
      boolean isrs = stmt.execute();
      stmt.close();
      System.out.println("Replacement of JAR succeeded");
      con.commit();
      con.close();
    }
    catch (Exception e)
    {
      System.out.println("Replacement of JAR failed");
      e.printStackTrace ();
    }
  }
}