DB2 Connect Quick Beginnings for UNIX**

Running Java Programs

You can develop Java programs to access DB2 databases with the appropriate Java Development Kit (JDK) on AIX, HP-UX, Linux, OS/2, PTX, Silicon Graphics IRIX, Solaris Operating Environment, or Windows 32-bit operating systems. The JDK includes Java Database Connectivity (JDBC), a dynamic SQL API for Java.

For DB2 JDBC support, you must include the DB2 Java Enablement component when you install the DB2 client. With DB2 JDBC support you can build and run JDBC applications and applets. These contain dynamic SQL only, and use a Java call interface to pass SQL statements to DB2.

The DB2 Application Development Client provides support for Java embedded SQL (SQLJ). With DB2 SQLJ support and DB2 JDBC support you can build and run SQLJ applications and applets. These contain static SQL and use embedded SQL statements that are bound to the DB2 database.

Java can also be used on the server to create JDBC and SQLJ stored procedures and user-defined functions (UDFs).

Building and running different types of Java programs requires support from different components of DB2:

For detailed information on building and running JDBC and SQLJ programs refer to the Application Building Guide. For more information on DB2 programming in Java, refer to the Application Development Guide. This covers creating and running JDBC and SQLJ applications, applets, stored procedures and UDFs.

For the latest, updated DB2 Java information, visit the Web site at: http://www.ibm.com/software/data/db2/java

Configuring the Environment

To build DB2 Java programs, you need to install and configure the appropriate version of a Java Development Kit (JDK) on your development machine. To run DB2 Java applications, you must install and configure the appropriate version of either a Java Runtime Environment (JRE) or JDK on your development machine. The following table lists the version of the JDK that is appropriate for your development machine:

AIX
The IBM AIX Developer Kit, Java Technology Edition, Version 1.1.8. On AIX systems that do not have a JDK installed, this JDK is automatically installed with the DB2 Application Development Client.

HP-UX
The HP-UX Developer's Kit for Java, Release 1.1.8, from Hewlett-Packard.

Linux
The IBM Developer Kit for Linux, Java Technology Edition, Version 1.1.8.

OS/2
The IBM Java Development Kit for OS/2, version 1.1.8, which is available on the product CD-ROM.

PTX
The ptx/JSE, Version 1.2.1, from IBM.

SGI IRIX
The Java 2 Software Development Kit for SGI IRIX, version 1.2.1, from SGI.

Solaris Operating Environment
The Java Development Kit for Solaris, version 1.1.8, from Sun Microsystems.

Windows 32-bit operating systems
The IBM Developer Kit for Windows 32-bit operating systems, Java Technology Edition, Version 1.1.8. When you install the DB2 Application Development Client, this JDK is automatically installed in the sqllib\java\jdk directory.

For information on installing and configuring any of the above JDKs, please refer to: http://www.ibm.com/software/data/db2/java

For all supported platforms, you must also install and configure a DB2 client with the DB2 Java Enablement component. To bind SQLJ programs to a database, you must install and configure a DB2 Administrative Client with the DB2 Java Enablement component.

To run DB2 Java stored procedures or UDFs, you also need to update the DB2 database manager configuration to include the path where the JDK version 1.1 is installed on your development machine. You can do this by entering the following on the command line:

On UNIX platforms:

   db2 update dbm cfg using JDK11_PATH /usr/jdk

where /usr/jdk represents the path where the JDK is installed.

On Windows and OS/2 platforms:

   db2 update dbm cfg using JDK11_PATH C:\sqllib\java\jdk

where C:\sqllib\java\jdk represents the path where the JDK is installed.

You can check the DB2 database manager configuration to verify the correct value for the JDK11_PATH field by entering the following command:

   db2 get dbm cfg

You may want to pipe the output to a file for easier viewing. The JDK11_PATH field appears near the beginning of the output. For more information on these commands, refer to the Command Reference.



Figure 00002674 not displayed.

On Solaris Operating Environment, some Java Virtual Machine implementations do not work well in programs that run in a "setuid" environment. The shared library that contains the Java interpreter, libjava.so, may fail to load. As a workaround, you can create symbolic links for all needed JVM shared libraries in /usr/lib, with a command similar to the following (depending on where Java is installed on your machine):
   ln -s /opt/jdk1.1.3/lib/sparc/native_threads/*.so /usr/lib

For more information on this and other workarounds available, please visit: http://www.ibm.com/software/data/db2/java

To run Java programs, the following environment variables are automatically updated during DB2 installation on OS/2 and the Windows Operating System, and during instance creation on UNIX platforms.

On UNIX platforms:

On Windows and OS/2 platforms:

In order to build and run SQLJ programs, CLASSPATH is also automatically updated to include these files:

On UNIX platforms:

On Windows and OS/2 platforms:

Java Applications

Start your application from the desktop or command line by running the Java interpreter on the executable program with this command:

   java prog_name

where prog_name is the name of the program.

The DB2 JDBC driver handles the JDBC API calls from your application and uses the DB2 client to communicate the requests to the server and receive the results. An SQLJ application must be bound to the database before it is run.

Java Applets

Because Java applets are delivered over the web, a web server must be installed on your DB2 machine (server or client).

To run your applet, make sure your .html file is properly configured. Start the JDBC applet server on the TCP/IP port specified in the .html file. For example, if you specified:

   param name=port value='6789'

then you would enter:

   db2jstrt 6789

You must ensure that your working directory is accessible to your web browser. If it is not, copy your applet's .class and .html files into a directory that is accessible. For SQLJ applets, you must also copy the profile .class and .ser files as well.

Copy the sqllib/java/db2java.zip file into the same directory as these other files. For SQLJ applets, also copy the sqllib/java/runtime.zip file into this directory. Then on your client machine start your web browser (which supports JDK 1.1) and load the .html file.

When your applet calls the JDBC API to connect to DB2, the JDBC driver establishes separate communications with the DB2 database through the JDBC applet server residing on the DB2 server. An SQLJ applet must be bound to the database before it is run.


[ Top of Page | Previous Page | Next Page ]