UD01 - DB2 for LUW - Development for Applications Programmers - 5 Days

Course Description

This course provides the applications programmer with an in-depth knowledge of the DB2 development process. It is aimed at programmers who need to code or support DB2 application programs and/or Stored Procedures written in SQL/PL or Java.


Pre-requisites

The delegate should be familiar with the host environment, together with a working knowledge program development using Java.


Objectives

The aim of this course is to provide the programmer, unfamiliar with DB2, with the necessary skills required to define, access and manipulate DB2 data, either via an application program or using the Command and Control Centres.

On completion of this course the student will be able to:

  • set up a DB2 test environment, using correctly defined tables, views, indexes, synonyms and aliases
  • code SQL statements to read and manipulate DB2 data
  • import and export DB2 data
  • develop, prepare and execute Java DB2 programs
  • code Stored Procedures written in SQL-PL and Java
  • use Query Result Sets within Stored Procedures
  • use IBM Data Studio to generate Stored Procedures
  • bind Stored Procedure packages
  • use non-scrollable and scrollable cursors
  • describe the locking process used by DB2
  • use the DB2 for Windows GUI Toolset
  • use the Command Line Processor
  • populate tables using DB2 Utilities
  • monitor application performance


Environment

DB2 running in a Linux, Unix or Windows environment.


Customisation

For on-site courses (i.e. at your premises), we are more than happy to tailor the course agenda to suit your exact requirements. In many cases, we are able to build your in-house standards and naming conventions into the delivered course.


Course Details

DB2 INSTANCES
DB2 INSTANCES
What Is An Instance?
Setting Up Instances

DATABASE DEFINITION
The Structure Of DB2 Objects
Database Definition
Default Tablespaces
Database Placement
Automatic Storage Databases
Database Creation Using IBM Data Studio
Database Definition Tasks
Altering a Database
Database Connectivity - Connect vs Activate
Catalog Tables

TABLESPACE DEFINITION
Tablespace Organisation
Data Placement - SMS or DMS?
Data Placement Considerations
Containers, Pages And Extents
Create Tablespace Command
Create Tablespace Parameters
Sms Tablespace Examples
Dms Tablespaces
Automatic Storage Tablespaces
Dms Minimum Space Requirements
Dms Maximum Space

TABLE / INDEX DEFINITION
Table Definition
Table / Column Names
Copying Table Definitions
Table Authority
Db2 Column Types
Null Values
Null and Default Compression
Compression - Row Format
Has Compression Been Switched On?
Lob Data Options
The Alter Table Statement
Advanced GUI Alter Table Functionality
The Rename Table Statement
Global Temporary Tables
Declared Temporary Tables
Declared Temporary Table Considerations
Declared Temporary Tables - Comparisons
Listing Table / Tablespace Information
Schema Definition
View Definition
Creating A View Of Two Tables
Read Only Views
View Restrictions
Views - Check Options
Alias Definition
Indexes
Index Organisation - The B Tree Index
Index Clustering
Index Definition

RUNNING SQL AND COMMANDS
Connecting To The Database
Using IBM Data Studio to run SQL Scripts
The DB2 Command Window and Command Line Processor
Command Line Syntax
On-Line Help
Interactive / Non-Interactive Modes
Clp Option Flag
Clp Termination

DATA MANIPULATION LANGUAGE
SQL - Structured Query Language
SQL Features
SQL Query Results
DB2 Environments
The Select Statement
The Where Clause
Special Operators
Not Operand
In Operand
Like Operand
Between Operand
User Keyword
Statements using Nulls
SQL Built-In Functions
Using 'Distinct'
Group By Clause
Group By Rollup
The Grouping Function
Group By Cube
Group By Grouping Sets
Having Clause
Order By Clause
Fetch First Clause
The Values Statement
The Update Statement
The Delete Statement
The Insert Statement
Column Functions (Scalar Functions)
Working with Date, Time and Timestamp Columns
DB2 Special Date/Time Registers
Current Date
Current Time
Current Timestamp
DB2 Join
Inner Joins
Outer Joins
Outer Join - Where Clause
Nested Table Expression
SQL Union / Intersect / Except
Subqueries
Subqueries using In
Exists
The 'All' Subquery
The 'Any' or 'Some' Subquery
Common Table Expressions
Recursive SQL

MOVING DATA
Import / Export Utilities
Import Utility Syntax
Import Authorities
Export Utility Syntax
Export Authorities
Load Utility
Load Utility Features
Load Examples
Load Utility Syntax
Recovering from Load Failure / Load Pending
Load Utility and Referential / Check Constraints:
Load Authorities
Load / Import Differences

APPLICATION PROGRAMMING
Db2 Environments
Single Row Selects
Sql Communication Area
Host Variable Declaration
Cursor Selects
Declare Cursor
Open Cursor
Fetch A Row
Row Update
Row Deletion
Close Cursor
With Hold Option
Fetch First Clause
The Optimize Statement
Precompiling A Program
Binding A Program
Levels Of Optimisation
Run Time Reoptimization - Bind Option REOPT

JAVA - JDBC PROGRAMMING
Database Environments
Dynamic SQL - What is JDBC?
What are JDBC Drivers?
JDBC Driver Types
The JDBC API
JDBC SQL Statements
Using the Statement Class to Select Rows
The DB2 Universal Driver
Running SQL Statements
Using the Statement Class to Update Rows
Processing Result Sets
Jdbc Cursor Operations
Cursor Scroll Types
Cursor Concurrency Types
Cursor Holdibility Types
Using the PreparedStatement Class
Handling NULL Values
Handling SQL Errors
Handling SQL Warnings
Transaction Control
Transaction Example
Isolation Levels
Calling A Stored Procedure From Java
Setting Stored Procedure Input / Inout Parameters
Registering Stored Procedure Output / Inout Parameters
Stored Procedures - Handling Nulls
Java - Handling Result Sets
Testing For Optional Result Sets
DataSources
Java Naming and Directory Interface - JNDI
Setting Up Connection Pooling using DataSources
Getting Database Connections via a DataSource

JAVA SQLJ PROGRAMMING (Optional)
SQLJ Programming - Development Cycle
SQLJ Support
Single Row Selects
Cursor Selects
Sqlj Cursor Technique 1 - JDBC Result Set
Sqlj Cursor Technique 2 - Sqlj Result Set
Positioned Updates using Cursors
Positioned Update Restrictions
Fetch First Clause
The Optimize Statement
Table Names In Application Programs
Precompiling An SqlJ Program
Binding A Package
Levels Of Optimisation
Run Time Reoptimization - Bind Option REOPT
Identifying A Collection Within A Program

SCHEMAS AND PATHS
Schemas
The Grant Schema Statement
Schema Path - Bind Option
Current Path - Special Register
Overriding the Search Path
Set Current Schema
Set Current Package Path

STORED PROCEDURE DEFINITION
The Create Procedure Statement
Stored Procedure Parameters
Allowable SQL Statements
Create Procedure Example
The Alter Procedure Statement
Deleting a Stored Procedure Definition
Defining a Java Stored Procedure
Java Stored Procedures - Jar Installation

JAVA STORED PROCEDURES
Calling A Stored Procedure From Java
Setting Stored Procedure Input / Inout Parameters
Registering Stored Procedure Output / Inout Parameters
Stored Procedures - Handling Nulls
Java - Handling Result Sets
Testing For Optional Result Sets
DataSources
Java Naming and Directory Interface - JNDI
Setting Up Connection Pooling using DataSources
Getting Database Connections via a DataSource

CODING PROCEDURES IN SQL/PL
The SQL Procedures language
An SQL Procedure Example
Building SQL Procedures?
JCL Example
SQL Procedure Supported Statements
Terminating Statements in an SQL procedure
Simple DML Statements
Selecting Data - Singleton Selects
Selecting Data - Cursor Operations
The Update Statement
Update with Subselect
The Delete Statement
The Insert Statement
The Mass Insert Statement

SQL/PL REFERENCE
Begin and End Statements (Compound Statements)
Declaring Host Variables
Assigning Values to Variables - The SET Statement
CASE Statement
Comments
FOR Statement
GET DIAGNOSTICS Statement
GOTO Statement
IF Statement
Comparison Operators
LEAVE and ITERATE Statements
LOOP statement
REPEAT Statement
RETURN Statement
WHILE statement
Handling Errors in an SQL Stored Procedure
Testing for Errors - SQLCode and SQLState
The Declare Handler Statement
Condition Handler Execution Path
Declaring Conditions for Handlers
Dynamic SQL statements
Returning Result Sets
Processing Result Sets From Other Stored Procedures
SIGNAL Statement and Message_Text Variable
RESIGNAL Statement

DYNAMIC RESULTS SETS
Dynamic Results Sets
Objects From Which You Can Return Result Sets
Requirements for Dynamic Result Sets
Cursor Processing Within the Stored Procedure
Dynamic Result Set Embedded SQL Statements
Query Results Sets Example
Declare Cursor With Return
Definition of Result-Set-Locator Variables
Associate Locators
The Allocate Cursor Statement
Using Global Temporary Tables
Declared Temporary Tables
Declared Temporary Table Enhancement
Declared Temporary Table Considerations
Declared Temporary Tables - Comparisons

IBM Data Studio
Overview
Building DB2 Stored Procedures and Functions
Creating a New Stored Procedure or Function
The SQL Assistant
Building The Stored Procedure
Debugging Stored Procedures
Setting Breakpoints

MATERIALIZED QUERY TABLES
What Are Materialized Query Tables?
MQT Features
Creating an MQT
Create MQT Example
Altering an MQT
Alter MQT Example
MQT Fullselect Features / Restrictions
Refresh Table
Populating User Maintained MQTs
Automatic Query Rewrite using MQT
Enabling Automatic Query Rewrite
Enabling Automatic Query Rewrite - DDL Options
Enabling Automatic Query Rewrite - Special Registers
AQR - Using Both Registers
Enabling Automatic Query Rewrite - System Properties
Enabling Automatic Query Rewrite - Query Properties
Registering Existing Tables as MQT
Maintenance of MQTs using Staging Tables

LOCKING
Implications Of Concurrent Processing
Database Manager Locks
Objects Of Locks
Lock Modes
Lock Example
Lock Compatibility
Isolation Levels
Lock Escalation
The Lock Table Statement
Commit Points
Lock Wait And Deadlocks
Savepoints
Savepoints - Considerations and Restrictions
The Quiesce Utility
SHARE

DATA INTEGRITY
Referential Integrity
The Primary Key
The Foreign Key
Referential Integrity Rules
Referential Integrity Constraint Names
Self Referencing Referential Structures
Referential Integrity Performance
Check Constraints
Check Constraint Syntax
Allowable Check Constraints
When Are Check Constraints Enforced
Integrity Pending (aka Check Pending) State
The Set Integrity Command
Running Set Integrity Via IBM Data Studio
Informational Constraints

APPLICATION PERFORMANCE
The Db2 Optimizer
Levels Of Optimisation
Operational Utilities
Rebinding
The Runstats Utility
Runstats Parameters
Runstats - Sampling Options
Runstats - Statistics Profiling
Runstats - Throttling
Runstats Profiling Examples
Automatic Statistics Collection
Automatic Statistics Profile Generation
The Reorgchk Utility
The Reorg Utility
Offline / Online Table Reorg
Index Reorg

DB2 TOOLS
IBM Data Studio
IBM Data Studio Web Console


Course Format

The course contains many practical exercises to ensure familiarity with the product. Initially students create Tables and Indexes, and then proceed to develop Java or C programs accessing the data held on the DB2 Tables. On completion of this course students will be ready to start the development of application programs accessing DB2 data.

The comprehensive Student Guide supplied is fully indexed serving as a useful reference tool long after the course has finished. Delegates will also be able to access a free help-line with technical questions relating to topics covered on the course.


Course Enquiry