Chapter 4. Deploying applications with DB2 153
Example 4-3 The command file, jmigrate.cmd, used to start the Java application
// Step 1 : Setting up the path
setlocal
set path=jre1.6.0_05\bin
// Step 2 : Start the application
java -cp "itso.jar;db2\db2jcc.jar" ibm.itso.sg247653.MigrateExecuter %1 %2
compare %3 %4
򐂰Step 1: Setting up the path:
We set the path variable to point to the directory where the Java runtime
environment is located. The initial line setlocal is just for ensuring that any
settings within the command file are local to this file.
򐂰Step 2: Starting the application:
The -cp option to Java is the classpath that tells Java where to look for the
application components. We must supply four parameters to the command
file:
–server:port
database alias
– userid
–password
Output from a successful test of the deployed application is listed in Example4-4.
The important part in this example is the ability to connect to the database. The
logic within the application is not essential at this point; this is discussed in “Java
sample application: Automating update” on page247.
Example 4-4 Successful test of our deployed application
C:\javaapp>jmigrate 9.43.86.48:50000 itso db2inst1 ***
Connected to : jdbc:db2://9.43.86.48:50000/itso
------------- CHANGE REPORT -------------
**NO NEW TABLES
**NO REMOVED TABLES
CHANGED TABLES :
- ITSO.STAFF
------------- END OF REPORT --------------
Connection reset
OK !
In case of any error, we will not get a Change Report as listed. Instead we will
see an error message and a Java stack trace.
The Java application, excluding the Java runtime environment, is available for
download at the IBM Redbooks Web site. Refer to AppendixB, “Additional
material” on page 267 for the download instructions.