English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
JDBC drivers implement the defined interfaces in the JDBC API for interacting 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.
The JDK included Java.sql The 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 various operating systems and hardware platforms where Java runs. Sun classified the implementations into four types, namely1,2,3and4Below, we will explain-
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.2JDBC included-ODBC Bridge is a good example of this driver.
No tipo 2In the driver, the JDBC API calls are converted to the unique native C / C ++ API calls. These drivers are usually provided by the database vendor and are similar to JDBC-ODBC Bridge. Supplier-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 Type 2Driver can improve speed because it eliminates the overhead of ODBC.
The Oracle Call Interface (OCI) driver is a Type 2Driver example.
No tipo 3No driver uses a three-tier method 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.
Este driver é muito flexível, pois não requer a instalação de nenhum código no cliente, e um único driver pode realmente fornecer acesso a múltiplos bancos de dados.
Você pode considerar o servidor de aplicativo como um 'proxy' JDBC, o que significa que ele faz chamadas para o aplicativo cliente. Portanto, você precisa de algumas informações sobre a configuração do servidor de aplicativo para usar eficazmente este tipo de driver.
Seu servidor de aplicativo pode usar1,2ou4O driver do tipo Java se comunica com o banco de dados, entender as diferenças subtis pode ser útil.
No tipo 4No driver, o driver puramente baseado em Java se comunica diretamente com o banco de dados do fornecedor através de conexões de soquete. Este é o driver mais eficiente para o banco de dados, geralmente fornecido pelo próprio fornecedor.
Este driver é muito flexível, você não precisa instalar software especial no cliente ou no servidor. Além disso, esses drivers podem ser baixados dinamicamente.
MySQL Connector/Driver 4O driver J é do tipo4Driver de classe.
Se você precisar acessar um tipo de banco de dados, por exemplo Oracle, Sybase ou IBM, o tipo de driver preferido4.
Se o seu aplicativo Java acessar vários tipos de bancos de dados ao mesmo tempo, o tipo3é o driver preferido.
Se o seu banco de dados ainda não pode usar3ou4No caso do driver tipo2O driver é muito útil.
Tipo1O driver não é considerado um driver de nível de implementação, geralmente é usado apenas para fins de desenvolvimento e teste.