Types of connecting to DB2 using java

Source: Internet
Author: User
Tags db2 client db2 connect

This article will describe the basic types of connecting to DB2 in java. There are four types for your reference.

First: at present, IBM has not provided the JDBC driver for TYPE 1.

Type 2 driver: COM. ibm. DB2.jdbc. app. DB2Driver. The driver is also located in the package DB2java.zip. JDK must be able to access DB2's DB2jdbc. dll and so on.

Usage:

Class. forName ("COM. ibm. DB2.jdbc. app. DB2Driver"). newInstance ();
String url = "jdbc: DB2: sample ";
Connection con = DriverManager. getConnection (url, user, password );

The TYPE 2 driver enables Java applications to call db2through JDBC. The call to DB2 JDBC type 2 driver is converted to a Java local method. java applications using this driver must run on a DB2 client, and JDBC requests are forwarded to the DB2 server through this client.

Before using the DB2 JDBC application driver to access the data source in the DB2 UDB for iSeries or DB2 for OS/390 or z/OS environment, you must install DB2 Connect Version 8. DB2 JDBC type 2 driver supports most of the JDBC and SQLJ functions described in the JDBC 1.2 specification, and supports some functions described in the JDBC 2.0 specification.

Type 3 Driver: COM.ibm.DB2.jdbc.net. DB2Driver, which is located in the package DB2java.zip.

Usage:

Class. forName ("COM.ibm.DB2.jdbc.net. DB2Driver"). newInstance ();

The target connection DB2 system listens on the default port 6789 // you need to start the DB2jstrt command on the database server to enable the network port.

String url = "jdbc: DB2: // host: 6789: SAMPLE ";
Connection con = DriverManager. getConnection (url, user, password );

Type 4 Driver: com. ibm. DB2.jcc. DB2Driver, which is located in the package DB2jcc. jar.

In this case, the database encoding is UTF-8. Otherwise, an error is returned!

Usage:

Class. forName ("com. ibm. DB2.jcc. DB2Driver"). newInstance ();
String url = "jdbc: DB2: // host: 50000/SAMPLE ";
Connection con = DriverManager. getConnection (url, user, password );

The above content is an introduction to the four types of java connection to DB2. I hope you will have some gains.
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.