Avoid Type 1 and Type 3 Drivers
Sun classifies JDBC drivers into four categories, as shown in Table 4-1.
|
Driver |
Description |
|
Type 1 |
A bridge between JDBC and another database-independent API, such as ODBC. The JDBC-ODBC driver that comes with the Java SDK is the primary example of a Type 1 driver. |
|
Type 2 |
Translates JDBC calls into native API calls provided by the database vendor. |
|
Type 3 |
Network bridges that enable an application to take advantage of the WORA (write once, run anywhere) capabilities of Type 4 drivers, even when your database of choice supports only Type 2 drivers. |
|
Type 4 |
Talks directly to a database using a network protocol. Because it makes no native calls, it can run on any Java Virtual Machine (JVM). |
Most programmers learn JDBC using the JDBC-ODBC Bridge, which is a Type 1 JDBC driver. Nevertheless, the JDBC-ODBC Bridge is a bridging driver. In other words, it’s a driver that falls into the Type 1 or Type 3 categories. These types of drivers provide much weaker database performance than direct access drivers, and the reason for the weakness is fairly simple: bridging technologies require more hops to communicate with the database.
Though avoiding Type 1 and Type 3 drivers is a good rule of thumb, sometimes they cannot be avoided. Not all databases are supported by a Type 2 or Type 4 driver. For example, if you want an application to talk to Microsoft Access, you must use a Type 1 or Type 3 driver.
When to use a Type 1 or Type 3 driver ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access