You export your Java application
to a directory on your computer that is outside the Java project. Then you configure your Java environment to run your application
in the outside directory.
Before you beginEnsure that you have the following
software installed on the computer that runs your Java application:
- Java developer kit version
1.5 or later
- IBM® Data Server Driver for
JDBC and SQLJ Version 3.57
In the previous module, you created a Java project that contains a Java application in the workbench.
In
this lesson, you export your Java application
to a directory on your computer, configure the Java environment on your computer, and run the
application against the SAMPLE DB2® database.
To run your Java application
outside the workbench environment:
- Create a test directory that is named C:\pureQuery-test for
the Java application and pureQuery
files.
- In the workbench, update the code in the MySample.java file
so that the Java application
can run outside the workbench.
- Change the default SQL statement that the application
runs.
Set the value of the variable i to
0 in the following code:
if ( args.length == 0) {
// value for the default SQL statement to run
i = 0 ;
- Disable the method call that uses pureQuery method DataVersion.
Add two slashes before myPdqVersion() ;
line of code, which calls DataVersion.
Connection myTestConn=null;
myTestConn=getConnection();
//print pureQuery information
// myPdqVersion() ;
- Export the Java application
as a JAR file that contains only the Java code
without DB2 driver files or
pureQuery Runtime files.
- In the Package Explorer, right-click the MySample.java file
and click .
- In the Export window, select ,
click Next.
- In the JAR file Specification window:
- In the Select resources to export pane,
ensure that only the MySample.java file is selected.
- Select Export generated class file and resouces.
- In the JAR file field, specify the output
file C:\pureQuery-test\mytestapp.jar.
- In the Options section, ensure only Compress
contents of the JAR file is selected.
- Click Finish to create the JAR
file.
The workbench creates the C:\pureQuery-test\mytestapp.jar JAR
file. The JAR file contains only the myTestApp\MySample.class file
and a MANIFEST.MF file.
- Add the JAR files for the JDBC driver the application to
the CLASSPATH.
- Open a command prompt window, and set the directory
to c:\pureQuery-test.
In the window,
enter the command cd c:\pureQuery-test.
- Add the files to the CLASSPATH by using the SET command.
For example, if the DB2 database driver JAR files are installed
in the
C:\DB2\drivers directory, add the files
to the CLASSPATH by using the following command. Enter the SET command
on a single line.
set CLASSPATH=C:\DB2\drivers\db2jcc_license_cu.jar;C:\DB2\drivers\db2jcc.jar;
C:\pureQuery-test\MyTestApp.jar;%CLASSPATH%;
- Run the application:
Enter the following
command in the command prompt window:
java myTestApp.MySample
The application runs. Output appears in the command
prompt window. The output is similar to the following example:
=======
case 0
case 0 - employee count: 36
Finished case 0
The application is not enabled with
pureQuery client optimization and does not use any pureQuery Runtime
capabilities.
Note: Do not close the command window. You use the
CLASSPATH environment variable set in the command window in the next
lesson.