3 using an application – IBM Data Server DB2 User Manual
Page 242

228
DB2 Deployment Guide
db2 -o- -l createdb.log connect reset
exit /b 0
Step 1:
We set up the DB2 environment by setting the environment variable DB2CLP 
to **$$**. The first statement, 
setlocal
, ensures that the environment
variables set in the script are local to the script.
Step 2:
We call another Windows script that creates the database. If any error occurs, 
we exit directly with the exit code from the sub-script.
Step 3:
If the database is created, we connect to it.
Step 4:
Once connected to the database, we execute the script 
itsodb.ddl
to create
the database layout and the database objects. Notice that we use the 
command line processor option
-c-
that turns off the autocommit.
Step 5:
Because we have turned off the autocommit, we have to explicitly commit the 
transaction.
Step 6.a:
Because we have turned off the autocommit, none of our changes in 
itsodb.ddl
have been applied. In case of any error, we can rollback the
transaction and reset the connection to the database.
Step 6.b:
The database including database layout and objects has been successfully 
created. We only have to reset the connection.
5.2.3 Using an application
DB2 provides a call level interface for C/C++ and COBOL, but not for Java. 
To create the database through a Java application, you have to either call an 
external C program or invoke the CREATE DATABASE command through the 
command line processor. We use the command line processor to create the 
database in our examples. Once the database is created, you can use JDBC to 
execute to DDL statements to create the database layout and the database 
objects.
In this section, we show and explain some key features in the Java code with 
code fragments. The complete Java samples with descriptive comments can be 
downloaded from the IBM Redbooks Web site. See Appendix B, “Additional 
material” on page 267 for the download instructions.
