Java Application Language Environment

Net.Data supports your existing Java applications with the Java language environment. With support for Java applets and Java methods (or applications), you can access DB2 through the Java Database Connectivity (JDBC**) API.

Details about JDBC are available from these Web sites:

Configuring the Java Language Environment

To use the Java language environment, you need to verify the Net.Data initialization settings and set up the language environment.

Verify that the following configuration statement is in the initialization file, on one line:

ENVIRONMENT (DTW_JAVAPPS)   ( OUT RETURN_CODE ) CLIETTE "DTW_JAVAPPS"

See Environment Configuration Statements to learn more about the Net.Data initialization file and language environment ENVIRONMENT statements.

Important: See Setting up the Java Language Environment to learn how to set up the Java language environment.

Calling Java Functions

The Java language environment provides a Remote Procedure Call (RPC)-like interface. You can issue Java function calls from your Net.Data macro with Net.Data strings as parameters and your invoked Java function can return a string. You must use the Net.Data Live Connection when you use the Java language environment (see Managing Connections) for more information about Live Connection).

To call Java functions:

  1. Write your Java functions.
  2. Create a Net.Data cliette for all your Java functions (Net.Data cliettes launch the Java Virtual Machine where your Java function runs).
  3. Define a cliette on the Java ENVIRONMENT statement in Live Connection configuration file.

    Each time you introduce new Java functions, you must recreate the Java cliette.

  4. Start Connection Manager.
  5. Run the Net.Data macro that invokes the Java language environment.

Creating the Java Function

Modify the Java function sample file UserFunctions.java, or create a new file modeled on the following example file, called myfile.java:

====================myfile.java====================
import mypackage.*
 public String myfctcall(...parameters from macro...)
{
 return ( mypackage.mymethod(...parameters...));
 }
 
public String lowlevelcall(...parameters...)
{
 string result;
  .......code using many functions of your package...
  return(result)
}
   

Java Language Environment File Structure

Net.Data creates several directories during the Net.Data installation. These directories include the files you need to create your Java functions, define the cliette, and run the macro with the Java language environment:

Table 12 describes the directory and file names for the files on your operating system.

Table 12. The Files Used for Creating Java Functions
Operating System File name Directory
OS/2 UserFunctions.java javaapps
launchjv.com connect
Windows NT UserFunctions.java javaclas
makeClas.bat javaclas
launchjv.bat connect
UNIX UserFunctions.java javaapps
launchjv javaapps

Defining the Java Language Environment Cliette

Modify the sample file, makeClas.bat, or create a new .bat file to generate a Net.Data cliette class, called dtw_samp.class, for all your Java functions. The following example shows how the batch file, CreateServer, processes three Java functions:

rem Batch file to create dtw_samp for Net.Data
java CreateServer dtw_samp.java UserFunctions.java myfile.java
javac dtw_samp.java

The batch file processes the following files, along with the Net.Data-supplied stub file called Stub.java to create dtw_samp.class.

Writing a JDBC application or applet is very similar to writing a C application using DB2 CLI or ODBC to access a database. The primary difference between applications and applets is that an application might require special software to communicate with DB2, for example, DB2 Client Application Enabler. The applet depends on a Java-enabled Web browser, and does not require any DB2 code installed on the client.

Your system requires some configuration before using JDBC. These considerations are discussed at the DB2 JDBC Application and Applet Support Web site:

http://www.ibm.com/software/data/db2/jdbc/db2java.html

Java Language Environment Example

After you have created the Java function, defined the cliette class, and configured Net.Data, you can run the macro containing references to the Java function. Important: Start Connection Manager before invoking the Net.Data macro.

In the following example, the function call, myfctcall calls the sample function provided with Net.Data, using the cliette DTW_JAVAPPS.

%FUNCTION (DTW_JAVAPPS) myfctcall( ....parameters from macro ....)
 
%{ to call the sample provided with Net.Data %}
%FUNCTION (DTW_JAVAPPS) reverse_line(str);
 
%HTML(report){
you should see the string "Hello World" in reverse.
@reverse_line("Hello World")
You should have the result of your function call.
@myfctcall( ... ....)
%}


[ Top of Page | Previous Page | Next Page | Index ]