08-01-2013, 10:47 AM
DB2 Java Stored Procedures
DB2 Java Stored.pdf (Size: 3.11 MB / Downloads: 312)
Java overview
Java is a cross-platform language developed by Sun. Most companies have
embraced Java, and are well on their way towards integrating Java with their
existing technology. IBM is no exception, having become a leader in the use
of Java technology.
Java is designed to be portable, and Java programs developed on one
platform can often run unchanged on many computer systems. The most
important characteristics that make Java portable are:
• Java compiles to machine-independent bytecode.
Java is typically compiled and executed in a two-step process. First, the
Java code is compiled to bytecode, which means an assembly language
for an idealized Java virtual machine (JVM). Second, this bytecode is
executed by a run-time system, which can be either an interpreter, that is,
an emulator for the JVM, or a “Just-In-Time” (JIT) compiler that first
compiles the bytecode to native code, then executes the result.
Summarizing, the two steps of this process can be done on totally
separate platforms.
• Java has a portable graphic library.
In many software systems, the biggest hindrance to portability is the user
interface. Interfaces have typically been developed using a native
windowing system rather than a cross platform graphics toolkit, because
until now, this was the most convenient and widely available option.
However, this often meant that distribution on a different operating system
required a complete rewrite of the GUI. The Java developers realized that
a truly portable language would need a standard graphics library, and
included one from the beginning of the language’s development.
• Java avoids hard-to-port constructs.
The Java specification defines the size of primitive data structures such as
booleans, doubles, unlike some languages that allow this to vary among
implementations. For objects, Java programs cannot inadvertently depend
on implementation-specific details such as the amount of memory an
object consumes, or the internals of how fields or functions are laid out
within an object.
Java and the OS/390 Platform
In this section, we describe the Java support available on the OS/390
platform, together with some of the additional utilities required to implement
Java stored procedures.
OS/390 UNIX System Services
OS/390 UNIX System Services is an optional, no-charge feature of OS/390
that supplies UNIX functionality on the OS/390 platform. It runs concurrently
with the MVS system as a separate task. Applications can run under USS; in
fact, some products require USS (and Java is one of these).
Enterprise Toolkit for OS/390
The Enterprise Toolkit for OS/390 (ET/390) is part of VisualAge for Java
Enterprise Edition for OS/390. ET/390 provides a number of facilities to allow
you to code and test enterprise Java applications on the S/390 platform.
Java and the UNIX Platform
Thousands of Java programs run on the UNIX platform. Many developers
work directly with the Java Standard Development kits available from Sun and
IBM to compile and test their Java programs. There are a number of add-on
utilities, such as native-code compilers, debuggers, visual builders,
performance analyzers, and other tools commonly found for programming
languages.
DB2 UDB for UNIX, Windows, OS/2 ships with a JDK. If another version is
desired, the database can be configured to use a JDK installed anywhere on
the system.
It is not necessary to use a native-code compiler to transform Java to
something that can be used by the database.
Java and the Windows NT Platform
Like the UNIX platform, many Java programs run on the UNIX platform. Many
developers work directly with the Java Standard Development kits available
from Sun and IBM to compile and test their Java programs. There are a
number of add-on utilities, such as native-code compilers, debuggers, visual
builders, performance analyzers, and other tools commonly found for
programming languages. VisualAge for Java is a widely popular GUI builder
that many developers run on Windows NT.
DB2 UDB for UNIX, Windows NT, and OS/2 all ship with a JDK. If another
version is desired, the database can be configured to use a JDK installed
anywhere on the system.
It is not necessary to use a native-code compiler to transform Java to
something that can be used by the database.
Java and DB2
This chapter provides some background information on Java database
connectivity and DB2 stored procedures, and introduces many of the
concepts used throughout the rest of the book.
Java database connectivity
Java database connectivity has matured to the extent that the developer now
has two alternative APIs for accessing a database from within a Java
application: SQLJ and JDBC.
JDBC is a component of the core Java API standard as defined by Sun, as it
is an integral part of the Java JDK. JDBC does not directly embed SQL in the
Java code, but implements a set of methods (much like ODBC) that allow
SQL statements to be passed to the database, and results to be accessed
and manipulated.
SQLJ is an ANSI (and soon to be ISO) standard set of extensions to the core
Java classes that allow SQL to be directly embedded within Java applications,
in much the same way as it can be embedded in other languages such as
COBOL and PL/1.
This book will cover Java stored procedure support within DB2, but it is
important to know that you can also make extensive use of JDBC and SQLJ
from stand-alone Java programs.
DB2 JDBC programs
The JDBC API is a standard Java interface for connecting to relational
databases from Java. JDBC consists of two parts: the high level API and
multiple low-level drivers for connecting to different databases. It specifies
Java interface, classes, and exceptions to support connections, SQL data
manipulation language (DML), SQL data definition language (DDL),
processing of data result sets, and so on.
JDBC supports use of dynamic SQL so it can deal with situations where you
do not know the table and column names at the time the application is written.
Unlike static embedded SQL programs, dynamic SQL programs involve the
execution of at least some SQL statements that are not completely known
until runtime. Dynamic SQL allows you to create general and flexible
applications, because the full text of the SQL statement does not have to be
known at compilation time.