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:
http://www.ibm.com/software/data/db2/java/
http://splash.javasoft.com/jdbc/
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.
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:
Each time you introduce new Java functions, you must recreate the Java cliette.
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) }
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 |
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
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( ... ....) %}