JDBC Driver Types, jdbcdrivertypes

Source: Internet
Author: User

JDBC Driver Types, jdbcdrivertypes

  • JDBC Driver Types
    • Type1: JDBC-ODBC Bridge Driver
    • Type2: JDBC-Native API
    • Type3: JDBC-Net Pure Java
    • Type4: 100% Pure Java
    • Model diagram in the official document
  • How to select a JDBC driver

 

I believe that anyone who has worked in Java Development knows about the JDBC Driver: It is the middleware for Java programs to access the database. The JDBC driver enables the Java program to open the database connection and sends SQL (DDL, DML) or database commands. The execution results are returned in the Java data type. From the implementation point of view: it is the implementation of Java JDBC APIs, completed by a third-party database vendor.

 

JDBC Driver Types

Due to the diversity of operating systems and hardware platforms, Sun divides JDBC implementation into four types (Type1, 2, 3, 4 ). The following describes the four types respectively.

JDBC-ODBC Bridge Driver

For type1 drivers, the communication model is as follows:

 

 

1) A Database Server is installed on one Server.

2) The database client is installed on the local machine (the machine running the java program ).

  • · This client program is used to communicate with remote Database Server
  • · The client program has an ODBC driver.

3) when the Java program communicates with the ODBC driver on the client, a jdbc odbc bridge (type 1) is used)

 

That is to say, the Java program communicates with the ODBC driver on the client through the jdbc odbc bridge, and ODBC communicates with the remote database to complete the communication between Java and the database.

 

In the era when Java was just born, this method was very useful because the databases at that time only supported ODBC access. But now, this access method is rarely seen. If you want to practice this method, you can still.

For example, SQLServer, Access, and DB2 certainly support this method.

 

 

 

 

 

 

Type 2: JDBC-Native API

In this way, the jdbc api uses the JNI method, that is, the Java call is converted into a C/C ++ call to access the database. That is to say, the entire communication process is like this:

· Java code calls the JDBC API

· Jdbc api is converted to JNI call, that is, Type2 type driver call.

· Type 2 drivers access the database.

 

In this way, you also need to install the client because the driver (Type2-Native API implementation) is available in the client.

Compared with Type1, Type2 has less ODBC, so this method has less overhead.

 

For example, when PLSQL Developer is used, OCI (Oracle Call Interface) is used ).

 

 

Type 3: JDBC-Net pure Java

Type1, 2, and 4 are two-layer communication modes: local programs (including Java programs, drivers, and clients)-> database servers. However, Type 3 is a layer-3 Communication Mode:

 

JDBC Type1 and 2, 4 drivers are installed on the intermediate server to directly interact with remote databases. java uses the Type3 driver to call JDBC Type1, 2, 4, and 2 based on the network, in this way, the Java program communicates with the database.

 

Type 4:100% Pure Java

 

 

 

This method should be the most commonly used at present. Directly interact with the database through the JDBC driver. You also need to install the client or something.

 

Communication Model diagram in official documents

 

How to select the JDBC driver?

 

If you access a type of database, such as Oracle, Sybase, and IBM, type 4 is preferred.

If your Java program accesses multiple databases at the same time, Type 3 is a good choice.

If Type3 and 4 are unavailable, Type2 is a good choice.

Type 1 is rarely used now.

 

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.