Application Building Guide

JDBC Programs

Applets

DB2Applt demonstrates a dynamic SQL Java applet using the JDBC applet (or "net") driver to access a DB2 database.

To build and run this applet by commands entered at the command line:

  1. Ensure that a web server is installed and running on your DB2 machine (server or client).
  2. Modify the DB2Applt.html file according to the instructions in the file.
  3. Start the JDBC applet server on the TCP/IP port specified in DB2Applt.html; for example, if in DB2Applt.html, you specified param name=port value='6789', then you would enter:
       db2jstrt 6789
    
  4. Compile DB2Applt.java to produce the file DB2Applt.class with this command:
       javac DB2Applt.java
    
  5. Ensure that your working directory is accessible by your web browser. If it is not, copy DB2Applt.class and DB2Applt.html into a directory that is accessible.
  6. Copy the file %DB2PATH%\java\db2java.zip on OS/2 or Windows 32-bit operating systems, or sqllib/java/db2java.zip on UNIX, into the same directory as DB2Applt.class and DB2Applt.html.
  7. On your client machine, start your web browser (which must support JDK 1.1) and load DB2Applt.html.

As an alternative to steps (1), (5) and (7), you can use the applet viewer that comes with the Java Development Kit by entering the following command in the working directory of your client machine:

   appletviewer DB2Applt.html

You can also use the Java makefile to build this program.

Applications

DB2Appl demonstrates a dynamic SQL Java application using the JDBC application (or "app") driver to access a DB2 database.

To build and run this application by commands entered at the command line:

  1. Compile DB2Appl.java to produce the file DB2Appl.class with this command:
       javac DB2Appl.java
    
  2. Run the java interpreter on the application with this command:
       java DB2Appl
    

You can also use the Java makefile to build this program.

Client Applications for Stored Procedures

Spclient is a client application that calls the Java stored procedure class, Spserver , using the JDBC application driver. Before building and running this client application, build the stored procedure class on the server. See "Stored Procedures".

To build and run this client program by commands entered at the command line:

  1. Compile Spclient.java to produce the file Spclient.class with this command:
       javac Spclient.java
    
  2. Run the Java interpreter on the client program with this command:
       java Spclient
    

You can also use the Java makefile to build this program.

Client Applications for User-Defined Functions

UDFcli is the client program that calls the user-defined functions implemented in the user-defined function server program, UDFsrv , using the JDBC application driver. Before building and running this client application, build the user-defined function program, UDFsrv, on the server. See "User-Defined Functions (UDFs)".

To build and run this client program by commands entered at the command line:

  1. Compile UDFcli.java to produce the file UDFcli.class with this command:
       
       javac UDFcli.java
    
  2. Run the Java interpreter on the client program with this command:
       java UDFcli
    

You can also use the Java makefile to build this program.

Stored Procedures

Spserver demonstrates dynamic SQL PARAMETER STYLE JAVA stored procedures using the JDBC application driver. Stored procedures are compiled and stored on a server. When called by a client application, they access the server database and return information to the client application.

To build and run this program on the server by commands entered at the command line:

  1. Compile Spserver.java to produce the file Spserver.class with this command:
       javac Spserver.java
    
  2. Copy Spserver.class to the %DB2PATH%\function directory on OS/2 and Windows 32-bit operating systems, or to the sqllib/function directory on UNIX.
  3. Next, catalog the stored procedures by running the Spcreate.db2 script on the server. First, connect to the database:
       db2 connect to sample
    

    If the stored procedures were previously cataloged, you can drop them with this command:

       db2 -td@ -vf Spdrop.db2
    

    Then catalog them with this command:

       db2 -td@ -vf Spcreate.db2
    
  4. Then, stop and restart the database to allow the new shared library to be recognized. If necessary, set the file mode for the shared library so the DB2 instance can access it.
  5. Compile and run the Spclient client application to access the stored procedure class. See "Client Applications for Stored Procedures".

You can also use the Java makefile to build this program.


[ Top of Page | Previous Page | Next Page ]