English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
JDBC drivers implement the defined interfaces in the JDBC API to interact with the database server.
For example, you can open a database connection and interact with it by sending SQL or database commands using JDBC drivers, and then receiving the results using Java.
JDK included Java.sql The software package contains various classes that define its behavior, and its actual implementation is completed in third-party drivers. Third-party vendors implement java.sql.Driver interface.
The implementation of JDBC drivers varies due to the multiple operating systems and hardware platforms on which Java runs. Sun classified the implementations into four types, namely types1,2,3and4, which will be explained below-
In the type1In the driver, the JDBC bridge is used to access the ODBC driver installed on each client computer. To use ODBC, you need to configure the data source name (DSN) representing the target database on the system.
When Java was first introduced, it was a useful driver because most databases only supported ODBC access, but now it is recommended to use this type of driver only for experimental purposes or when there are no other available alternatives.
JDK 1.2The included JDBC-ODBC Bridge is a good example of this type of driver.
In Type 2In the driver, JDBC API calls are converted to database-specific native C / C ++ API calls. These drivers are usually provided by the database vendor and are compatible with JDBC-Suppliers' specific drivers must be installed on each client computer.
If the database is changed, the native API must be changed because it is specific to the database and is now outdated, but it can be used in the same way as the ODBC Bridge Type 2The driver can improve speed because it eliminates the overhead of ODBC.
Oracle Call Interface (OCI) driver is a Type 2Example of a driver.
In Type 3In the driver, a three-tier method is used to access the database. The JDBC client communicates with the middleware application server using standard network sockets. Then, the socket information is converted by the middleware application server into the call format required by the DBMS and forwarded to the database server.
This driver is very flexible because it does not require any code to be installed on the client, and a single driver can actually provide access to multiple databases.
You can consider the application server as a JDBC 'proxy', which means it makes calls to the client application. Therefore, you need some knowledge about application server configuration to effectively use this driver type.
Your application server may use1,2or4Type driver communicates with the database, understanding the subtle differences will prove to be helpful.
In Type 4The driver, the pure Java-based driver communicates directly with the vendor's database through socket connections. This is the highest performance driver available for databases, usually provided by the vendor itself.
This driver is very flexible, as you do not need to install any special software on the client or server. In addition, these drivers can be dynamically downloaded.
MySQL's Connector/J Driver is Type 4The driver. Due to the proprietary nature of its network protocol, database vendors usually provide4Class driver.
If you need to access a specific database type, such as Oracle, Sybase, or IBM, the preferred driver type4.
If your Java application accesses multiple types of databases at the same time, the type3is the preferred driver.
is not available in your database3Type or4Type driver, the type2The driver is very useful.
Type1The driver is not considered a deployment-level driver and is usually used only for development and testing purposes.