Building JDBC routines

You can use a Java™ makefile or the javac command to build JDBC routines. After you build those routines, you need to catalog them.

About this task

The following steps demonstrate how to build and run these routines:
  • The SpServer sample JDBC stored procedure
  • The UDFsrv sample user-defined function, which has no SQL statements
  • The UDFsqlsv sample user-defined function, which has SQL statements

Procedure

  • To build and run the SpServer.java stored procedure on the server, from the command line:
    1. Compile SpServer.java to produce the file SpServer.class with this command:
         javac SpServer.java
    2. Copy the SpServer.class file to the sqllib\function directory on Windows operating systems, or to the sqllib/function directory on Linux® or UNIX operating systems.
    3. Catalog the routines by running the spcat script on the server.
      The spcat script connects to the sample database, uncatalogs the routines if they were previously cataloged by calling SpDrop.db2, then catalogs them by calling SpCreate.db2, and finally disconnects from the database. You can also run the SpDrop.db2 and SpCreate.db2 scripts individually.
    4. Stop and restart the database to allow the new class file to be recognized. If necessary, set the file mode for the class file to "read" so it is readable by the fenced user.
    5. Compile and run the SpClient client application to access the stored procedure class.
  • To build and run the UDFsrv.java user-defined function program (user-defined function with no SQL statements) on the server, from the command line:
    1. Compile UDFsrv.java to produce the file UDFsrv.class with this command:
         javac UDFsrv.java
    2. Copy UDFsrv.class to the sqllib\function directory on Windows operating systems, or to the sqllib/function directory on Linux and UNIX operating systems.
    3. Compile and run a client program that calls UDFsrv.

      To access the UDFsrv library, you can use the UDFcli.java JDBC application, or the UDFcli.sqlj SQLJ client application. Both versions of the client program contain the CREATE FUNCTION SQL statement that you use to register the user-defined functions with the database, and also contain SQL statements that use the user-defined functions.

  • To build and run the UDFsqlsv.java user-defined function program (user-defined function with SQL statements) on the server, from the command line:
    1. Compile UDFsqlsv.java to produce the file UDFsqlsv.class with this command:
         javac UDFsqlsv.java
    2. Copy UDFsqlsv.class to the sqllib\function directory on Windows operating systems, or to the sqllib/function directory on Linux and UNIX operating systems.
    3. Compile and run a client program that calls UDFsqlsv.

      To access the UDFsqlsv library, you can use the UDFsqlcl.java JDBC application. The client program contains the CREATE FUNCTION SQL statement that you use to register the user-defined functions with the database, and also contains SQL statements that use the user-defined functions.