DB2 UDB for Linux, Java Development Overview in Unix and Windows: V8.1 Update

xiaoxiao2021-03-06  68

Form: http://www-900.ibm.com/developerWorks/cn/dmdd/library/techarticles/0307zikopoulos/0307zikopoulos.shtml

DB2 UDB for Linux, Java Development Overview in Unix and Windows: V8.1 Update

Paul Zikopoulos and Grant Hutchison IBM Canada October 2003

© 2003 International Business Machines Corporation. All Rights Reserved.

Note: This article is a V8.1 update to the article DB2 and Java Database Connections (JDBC) overview.

Introduction

Relational databases play an important role in most applications that require persistent data storage, but they are not developed and selecting various programming models, frames and architectures. The priority of application development is usually determined by factors other than the relational database management system (RDBMS), such as for a particular task, is the selection J2EE or .NET as a programming model.

Recognizing that you might prefer a programming architecture and others may be passionate about another architecture. The policy taken by DB2® Universal DatabaseTM is to provide the best integration that contains any of the options you do.

This article specializes in the DB2 UDB environment to support this special topic.

DB2 UDB application development method

Although this may be too simple, the current application development mainly includes the following different programming types:

Develop applications based on J2EE programming models using Java. Develop Windows®, Web, WinForm, and .NET-based applications based on the current Microsoft® API set (ADO and ADO.NET). Develop applications using the C / C programming language and ODBC / CLI interface. Develop applications using the Borland Delphi / Kylix framework. Develop applications with an open source frame (Perl, Python and PHP, etc.) focus on Linux. Develop cross-platform business logic using Web services.

The advantage of DB2 UDB is that it supports all the development models above!

For JavaTM programmers, DB2 provides two application programming interfaces (APIs): JDBC and SQLJ. As defined in the Java 2 Standard Edition (Java 2, Standard Edition, J2SE) specification, JDBC is an essential component of the Java programming language. According to the standards defined, it is necessary to write a JDBC application that access DB2, the implementation of various Java classes and interfaces is required. This implementation is also known as JDBC drivers. DB2 UDB for Linux, UNIX® and Windows provide a set of JDBC drivers for this purpose. The JDBC driver is divided into an old / CLI driver and a new Universal JDBC Driver.

DB2 UDB Java support includes support for JDBC, JDBC is a dynamic SQL interface-independent dynamic SQL interface, which provides data access to your application by standardized Java method. JDBC is similar to DB2 CLI because you do not need to prepare application code, and you do not need to bind your package to the DB2 database. As a standard that is unrelated to the supplier, the JDBC application provides more portability - this is the advantages necessary for today's heterogeneous business infrastructure. During the execution of the JDBC application, the driver verifies the SQL statement for the currently connected DB2 database server. Any questions during access will be reported to the application as a Java exception with the corresponding SQLState and SQLCode. SQLJ is a standard development model for data access from Java applications. The SQLJ API is defined in the SQL 1999 specification. The new General JDBC driver provides support for JDBC and SQLJ APIs in an implementation. JDBC and SQLJ can interoperate in the same application. SQLJ provides a unique ability to develop and control access to the DB2 package level.

DB2 Java Access Method

DB2 provides a rich support for the Java programming environment. You can use one of the following methods to place the Java class into the module to access DB2 data:

DB2 server

Stored Procedure (JDBC or SQLJ) SQL Function or User-Defined Function (JDBC or SQLJ) Browser

JDBC-based Applet (JDBC) J2EE application server (such as WebSphere® Application Server)

Java ServerPages (JSP) (JDBC) servlet (SQLJ or JDBC) Enterprise JavaBeans (EJB) (SQLJ or JDBC)

You may ask "How do I start?".

First, install the DB2 UDB application development client (DB2 UDB Application Development Client) and connect it to UNIX, Linux, Windows, z / OSTM or OS / 400® DB2 UDB database. If you plan to access DB2 UDB for z / OS or DB2 UDB for OS / 400, use DB2 ConnectTM products that suits you. The DB2 UDB application development client contains all drivers required to develop C, COBOL, and Java applications.

If you intend to develop multi-layer applications using J2EE application servers (such as WebSphere Application Server), each application server requires DB2 UDB runtime client and DB2 UDB application development client.

After developing and tested the application, the next step is to determine the deployment topology. Various JDBC driver architectural types are defined in the specification. Let's study the available types of drivers, Java Development Toolbox (JDK) versions, and Java runtime environment (JRE).

JDBC driver reveals

Common roots for confusing Java is: JDBC has different versions, and the JDBC driver has different types that can be used by different versions of Java. Moreover, the new Java specifications are always developed because the related features are constantly expanded through the Java Community Process, http://www.jcp.org. JDBC version

DB2 Universal Database V8.1 supports JDBC V2.1 specification and part JDBC 3.0 specification. Using the general JDBC driver, fully supporting the planning of JDBC 3.0 requirements in progress.

The JDBC driver is authenticated as a component of the J2EE solution. The result of the driver authentication is always published on the Sun Compatibility website.

JDBC driver architecture

The JDBC driver architecture is divided into four types.

TYPE 1 TYPE 2 TYPE 3 TYPE 4

JDBC TYPE 1 driver

JDBC TYPE 1 driver is based on a JDBC-ODBC bridge. Therefore, the ODBC driver can be used in combination with such JDBC drivers (provided by Sun). IBM does not support Type 1 driver, so it is not a recommended environment. Figure 1 shows an example of a JDBC Type 1 driver:

Figure 1. JDBC TYPE 1 driver

JDBC TYPE 2 driver

The JDBC Type 2 driver relies on the operating system-specific libraries (shared libraries) to communicate with RDBMS. The application will load this JDBC driver, and the driver will use the shared library to communicate with the DB2 server. DB2 UDB for Linux, UNIX® and Windows® V8.1 provide two different Type 2 drivers:

The old / CLI JDBC driver is available in the file db2java.zip. Its real estate name is com.ibm.db2.jdbc.app.db2driver. The driver is currently used to perform J2EE authentication. Its alias "APP driver" is derived from a concept and its package name, which is: This driver will perform local connections through the local DB2 UDB client of the remote database. The general JDBC driver is available in file db2jcc.jar. Its real estate name is com.ibm.db2.jcc.db2driver. This driver is a new feature in DB2 UDB for Linux, UNIX, and Windows V8.1. In the initial implementation (V8.1), this driver is used to connect directly to the DB2 server using the Type 4 driver architecture. In DB2 V8.1.2, you can use this driver in the Type 2 architecture. One main reason for using this driver in the Type 2 architecture is to support local application performance and distributed transaction support. GM JDBC TYPE 2 drivers use com.ibm.db2.jcc.db2xadatasource and com.ibm.db2.jcc.db2connectionPoolDataSource to support distributed transactions and connect pools.

You can use the JDBC Type 2 driver to support JDBC applications. WebSphere Application Server also supports both Type 2 drivers. Note: No old / CLI TYPE 2 driver is enhanced in the future version.

Figure 2 shows a typical topology of an application using a JDBC Type 2 driver:

Figure 2. Application of using JDBC Type 2 driver

JDBC TYPE 3 driver

JDBC Type 3 driver is a pure Java implementation that must communicate with DB2 JDBC Applet Server (DB2 JDBC Applet Server) to access DB2 data. Such drivers are intended to enable Java Applets to access DB2 data sources. In the scheme shown in Figure 3, the application communicates with another machine installed with a DB2 client. Figure 3. Typical application solution using the Type 3 JDBC driver

JDBC Type 3 Driver is often referred to as "NET) driver", which is named by its package name com.ibm.db2.jdbc.net. DB2 V8.1 supports a network driver that can be used for JDBC applications.

The Type 3 driver requires the DB2JAVA.ZIP driver always in the same maintenance level as the DB2 Applet server. This is not a problem if the driver is used in the applet, because the browser downloads the corresponding db2java.zip file during the application execution. Many customers use the Type 3 driver instead of the Type 2 driver to avoid the required DB2 client installation and required DB2 Catalog Database commands, the latter is used to create the database necessary to use the old / CLI driver for TYPE 2 connection. Directory information. Currently, WebSphere Application Server and other J2EE servers do not support IBM Type 3 drivers because the driver does not support distributed transactions (JTA). The future version will not enhance the Type 3 driver.

We encourage the use of the General JDBC Type 4 driver to replace the Type 3 driver.

JDBC TYPE 4 driver

The Type 4 driver is only the JDBC driver for Java, which is directly connected to the database server. DB2 UDB for Linux, UNIX, and Windows V8.1 introduces a TYPE 4 driver called "Universal JDBC Driver". The general JDBC driver is available in file db2jcc.jar. It has a package called com.ibm.db2.jcc.db2driver.

Note that the general Type 2 and the General Type 4 driver have the same implementation class name. There are two ways to distinguish which drivers will be different from DB2 internally:

Use connection characteristics to determine if the connection uses a shared library (Type 2), or whether the driver will start direct connections from the Java application (Type 4). Use different connection URL patterns to indicate which of you want Type 2 and Type 4 behavior. TYPE 4 URL Mode example: String "JDBC: DB2: // Server1: 50000 / Sample" Requires the JDBC driver to connect the Java application directly to the DB2 server name "Sample", the database is located in DB2 In the DB2 instance on the server (hostname Server1), the DB2 server listens on port 50000. Sample of Type 2 URL Mode: String "JDBC: DB2: Sample". Information about DB2 servers ("Server1") and port ("50000") can be found in the DB2 client catalog.

A universal JDBC driver is an abstract JDBC processor that is independent of the driver type connectivity or target platform. A generic JDBC driver is a JDBC driver that is unrelated to the architecture for distributed and local DB2 UDB access. Because universal JDBC drivers are independent of any particular JDBC driver type connectivity or target platform, it supports all Java connectivity (Type 4 drivers) and JNI-based connectivity in a DB2 UDB driver instance (Type 2) driver). The driver can be used for standalone Java applications or multi-layer applications. Important: For DB2 UDB V8.1.2, the General JDBC driver requires the license JAR file and db2jcc.jar file in ClassPath. The following is the required license JAR file:

For Cloudscape ™ Network Server V5.1: db2jcc_license_c.jar for DB2 UDB V8 for Linux, UNIX and Windows servers: db2jcc_license_su.jar for DB2 UDB for iSeries® and z / OS servers (supplied with DB2 Connect and DB2 Enterprise Server Edition) : DB2JCC_LICENSE_CISUZ.JAR

The general-purpose driver can query the data library metadata directory and retrieve server error message by using the necessary stored procedures pre-installed on the target server.

These stored procedures are pre-installed for UDB V8 on Linux, UNIX, and Windows. For DB2 UDB FOR OS / 390® V6, PTF UQ72081 and UQ72082 must be installed. For DB2 UDB for OS / 390 and z / OS V7, PTF UQ72083 must be installed. The DB2 UDB V8 that is about to be launched will be pre-installed in advance. DB2 UDB for iSeries V5R1 requires PTF Si06308, Si06300, Si06301, Si06302, Si06305, Si06307, and Si05872. DB2 UDB for iSeries V5R2 requires PTF Si06541, Si06796, Si07557, Si07564, Si07565, Si07566, and Si07567. DB2 UDB for iSeries V5R3 will pre-install the required stored procedures.

The TYPE 4 JDBC driver implementation is shown in Figure 4. Note: Universal JDBC / SQLJ drivers (Type 4 and Type 2) for DB2 for z / OS AND OS / 390 require the appropriate license file (DB2JCC_LICENSE_CISUZ) from Linux, UNIX, and Windows. JAR). The license file is provided with DB2 Connect products.

Figure 4. TYPE 4 JDBC driver implementation

Java Development Toolbox (JDK) and Java runtime environment (JRE)

Each JDBC version has associated JDK / JRE.

JDBC 2.0 and JDBC 2.1 APIs are included in two packages:

Java.sql package (including core API; it is a JDBC 1.22 API enhancement) Javax.sql package (optional package, is used to support connection pool, distributed transaction, and other similar advanced features). J2SE (Java 2, Standard Edition, implemented in JDK 1.2 and later) Supports JDBC 2.0 and JDBC 2.1 core API, J2EE 1.3 supports JDBC 2.0 optional packages. JDBC 3.0 finally completed in May 2002 and has been incorporated into J2SE 1.4 and J2EE 1.4. Many customers use 1.3.1 Environment to develop and deploy Java applications. This is currently recommended by the DB2 Java application environment. A general JDBC driver requires a 1.3.1 environment. Note: Some plans for JDBC 3.0 APIs with Universal JDBC drivers are in progress in the JDK 1.4 environment.

Frequently Asked Questions & Solutions

Question 1: Where can I get the DB2 UDB JDBC TYPE 4 driver?

Answer 1: This driver is provided with the DB2 UDB client, you can also download the trial version of DB2 UDB Express or DB2 UDB Personal Developers Edition.

Answer 3: Using General JDBC drivers in DB2 UDB V8.1 supports updatable, scrolling cursors. If you are using DB2 UDB for Linux, UNIX, and Windows V7.x, you can use the old / CLI driver and the SetCursorname API to simulate updatable, scrolling cursors. We recommend that you migrate to a generic JDBC driver.

Question 4: Can I connect to DB2 UDB for Z / OS and OS / 390 using DB2 JDBC TYPE 4 driver?

Answer 4: Yes, you will need a DB2 Connect license.

Question 5: Which JDBC driver is the fastest?

Answer 5: The answer varies depending on the configuration. If the Java application is running on the same machine with the DB2 server, the universal Type 2 driver will have the best performance because it is possible to avoid TCP / IP overhead and thus increasing throughput. When the DB2 server is on a different machine, the performance of General Type 4 and Type 2 drivers is inconsistent. If you try to improve the overall performance of the Java application, you should always consider writing more efficient SQL statements, or using SQLJ or stored procedures.

Question 6: Where can I find information about DB2 UDB and supported Java environments?

Answer 6: Check the following website: http://www-3.ibm.com/software/data/db2/udb/ad/v8/java/.

Question 7: Is there any difference between the old / CLI driver and the general driver?

Answer 7: Fundamentally, they all offer JDBC 2.1 / J2EE 1.3 level API support. The universal driver provides the latest features of the JDBC 3.0 specification. There are also slight differences between drivers because new drivers are based on open database access criteria called DRDA (distributed relational database architectory, Distributed Relational Database Architecture). These differences are recorded here.

Question 8: How can I use a universal driver to track SQL statements?

Answer 8: You can use the DataSource or Connection characteristics to track. See the documentation for more information. Question 9: Why should I consider replacing the JDBC with SQLJ? How to start?

Answer 9: Please read the question to consider using SQLJ for DB2 developer garden articles in DB2 V8.1 Java applications.

Page

About author

Paul C. Zikopoulos is a major speaker from the IBM data management software department, and has won the award. He has seven years of DB2 experience and has written many magazine articles about DB2. Paul and people have the following books: DB2: The Complete Reference, DB2 Fundamentals Certification for Dummies, DB2 For Dummies, and A DBA's Guide to DataBases on Linux. Paul is a DB2 certified advanced technology expert (DB2 Certified Advanced Technical Expert, DRDA and Cluster / EEE), he is also a DB2 certified solution expert (DB2 Certified Solutions Expert, business intelligence and database management). You can contact him with Paulz_ibm@msn.com.

Grant Hutchison is the technical manager of IBM DB2 Integration Center in Toronto, he leads DB2 and WebSphere integration. He has 12 years of DB2 experience, serving developers, service analysts and consultants. Recently, he completed the software engineering graduate degree in the University of Waterloo.

转载请注明原文地址:https://www.9cbs.com/read-120025.html

New Post(0)