/* * Understand the basics * */For Java programmers, DB2 provides two application programming interfaces (APIs): JDBC and SQLJ.
JDBC:
JDBC drivers are divided into old //CLI drivers.
JDBC is a vendor-independent dynamic SQL interface that provides data access for your application through standardized Java methods.
JDBC is similar to DB2 CLI because you don't need to precompile application code or bind software packages to DB2 database.
As a vendor-independent standard, JDBC applications provide more portability-an important advantage of today's heterogeneous business infrastructure.
During the execution of JDBC application, the driver will validate SQL statements against the currently connected DB2 database server.
Any problems during access will be reported to the application as Java exceptions along with the corresponding SQLSTATE and SQLCODE.
SQLJ:
SQLJ is a standard development model for accessing data from Java applications.
SQLJ API is defined in SQL 1999 specification.
The new universal JDBC driver provides support for JDBC and SQLJ API in one implementation.
JDBC and SQLJ can interoperate in the same application.
SQLJ provides a unique ability to use static SQL statements for development and control access at the DB2 package level.
/**JDBC connection mode analysis * */
JDBC driver architectures are divided into four types: 1 type, type 2, type 3 and type 4.
Type 1:
The driver is based on JDBC-ODBC bridge.
Therefore, ODBC drivers can be combined with such JDBC drivers (provided by Sun).
IBM does not support the Type 1 driver, so it is not the recommended environment.
Type 2:
Drivers rely on operating system-specific libraries (shared libraries) to communicate with RDBMS.
The application will load this JDBC driver, which will use the * * * shared library to communicate with the DB2 server.
DB2 UDB for Linux, UNIX and WindowsV8. 1 provides two different Type 2 drivers:
& lt 1 & gt; The old /clijdbc driver is provided in the db2java.zip file.
The name of its implementation package is COM.ibm.db2.jdbc.app.DB2Driver
This driver has been used for J2EE authentication.
Its alias "app driver" comes from an idea and its package name.
The idea is that this driver will perform local connection through the local DB2 UDB client of the remote database.
A universal JDBC driver is provided in the<2> file db2jcc.jar
The name of its implementation package 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 was used for direct Java connection with DB2 server using the Type 4 driver architecture.
In DB2 V8. 1.2, you can use this driver in the Type 2 architecture.
One of the main reasons for using this driver in Type 2 architecture is for local application performance and distributed transaction support.
The universal JDBC Type 2 driver supports distributed transactions and connection pooling using com.ibm.db2.jcc.db2xadatasource and com.ibm.db2.jcc.db2connectionpooldatasource respectively. Note: The old /clitype2 driver will not be enhanced in future versions.
Type 3:
The driver is a pure Java implementation, and it must communicate with DB2 JDBC Applet server to access DB2 data.
This type of driver is designed to enable Java applet to access DB2 data sources.
It is usually called "network driver", which is named after its package name COM.ibm.db2.jdbc.net. DB2 V8. 1 supports network drivers and can be used in JDBC applications.
It is required that the db2java.zip driver is always at the same maintenance level as the DB2 Applet server.
If the driver is used in the applet, this is not a problem, because the browser will download the corresponding db2java.zip file during the application execution.
Many customers use the Type3 driver instead of the Type2 driver to avoid the necessary DB2 client installation and the necessary DB2 CATALOG DATABASE command, which is used to create the database catalog information needed for the Type 2 connection using the old //CLI driver.
Currently, WebSphere Application Server and other J2EE servers do not support IBM Type 3 driver because it does not support distributed transaction (JTA).
Future versions will not enhance the Type 3 driver.
Encourage the use of general JDBC type 4 drivers instead of type 3 drivers.
Type 4:
This driver is a JDBC driver only suitable for Java, which is directly connected to the database server.
DB2 UDB for Linux, UNIX and Windows V8. 1 introduced a Class 4 driver named "Universal JDBC Driver".
A universal JDBC driver is provided in the file db2jcc.jar
The implementation package is named com.ibm.db2.jcc.DB2Driver
Note that generic type 2 and generic type 4 drivers have the same implementation class name.
There are two ways to distinguish which driver DB2 will instantiate internally:
Use connection characteristics to determine whether the connection uses a * * * shared library (type 2) or whether the driver will start a direct connection from a Java application (type 4).
Important: as far as DB2 UDB V8. 1.2 is concerned, the universal JDBC driver requires a license JAR file and a db2jcc.jar file in the classpath.
The following license JAR files are required:
Cloudscape web server v 5.1:db2jcc _ license _ c.jar.
DB2 UDB V8:db 2 JCC _ license _ su. jar for Linux, UNIX and Windows servers.
DB2 UDB for iSeries and z/OS server (provided with DB2 Connect and DB2 Enterprise Server Edition): db2jcc _ license _ cisuz.jar * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Note: If you are using db2java.zip and the web server is using Tomcat, please rename db2java.zip to db2java.jar It is better to unpack and package the zip with jar command and directly change the file type (hehe, strictly speaking, this jar file is not grammatical.
There is also a general situation: if you use db2java.zip, you need to install the db2 client. If you use db2jcc.jar, you can connect directly through the network without installing a db2 client (if you use it on type2, you need to install a client) type2:
use
JDBC . driver class name = com . IBM . DB2 . JDBC . app . db 2 driver
jdbc.url=jdbc:db2:dataBaseName
If your tools are myeclipse and tomcat plug-ins, please copy db2jdbc.dll to %JAVA_HOME%/bin, otherwise it will not work.
& lt Do other types of drivers that use db2java.zip also have this problem? I don't know. I haven't tried. Try it sometime >;
use
JDBC . driver class name = com . IBM . DB2 . JCC . db 2 driver
jdbc.url=jdbc:db2:dataBaseName
Type 3:
Driver: db2java.zip
JDBC . driver class name = com . IBM . DB2 . JDBC . net . db 2 driver
JDBC . URL = JDBC:DB2://IP:6789/DBNAME
Note: to execute db2jstrt 6789 on the database (this sentence starts the db2jd process, 6789 is the default port for the server to listen to jdbc2 connections, or it can be set to any other port that does not conflict. )
Type 4:
Driver: db2jcc.jar
The database character set must be set to utf-8.
JDBC . driver class name = com . IBM . DB2 . JCC . db 2 driver
JDBC . URL = JDBC:DB2://IP:port/DBNAME