finally {

//Step 5 stmt.close(); con.close();

}

￿Step 1:

First of all we retrieve a connection to the database and from the connection we get a statement object. How to get a connection to the database can either be seen in the downloadable sample program or at the DB2 Infocenter.

￿Step 2:

We simply loop through the list of statements and execute them one by one.

￿Step 3:

If all the statements are executed successfully, we commit the work.

￿Step 4:

In case of an error, we rollback all the statements and display the message that caused the error.

￿Step 5:

No matter if all statements were run successfully or failed, we clean up the resources by closing the statement and the connection.

In Example 5-11 on page 230, the error handling is kept very simple, we just print the error messages to standard output.

Java sample applications

Our Java samples are packed in the itso.jar file along with a couple of Windows

command files that can be used to start the Java applications. To run this sample code, a Java runtime environment is required. A command file jstmt.cmd can be

used to execute a file containing the DDL or SQL statements, while the file jscript.cmd can be used to execute a shell script from within Java.

For a detailed description of the Java applications and the command files, see 5.6, “Samples overview” on page 251.

5.3 Deploying a database using a backup image

The easiest way to deploy a database is to make a simple restore. Some considerations are required when issuing a restore:

Chapter 5. Deploying pre-configured databases

231

Page 245
Image 245
IBM DB2 manual Deploying a database using a backup image, Java sample applications, 231