views:

342

answers:

6

I am very new to Java, when i was going through the JDBC section, i noticed that JDBC has different Drivers like

  1. Type 1 Driver
  2. Type 2 Driver etc.. to Type 4 Why did they get the name like Type 1, Type 2 etc.., Is there any logic?
+7  A: 

This page explains the different driver types pretty well.

Eric Petroelje
Good link, dude
Brian T Hannan
+1  A: 

http://en.wikipedia.org/wiki/JDBC_driver

Does not seem to be any logic, just plain laziness I guess!

UPDATE: The question was whether there was some logic to calling it type 1, type 2 etc instead of calling type apple, type orange :). I understand that the driver types are different and work/not work based on circumstances, but why the name "Type 1" instead of "Type JDBC-ODBC" or "Type JO" has no reason AFAIK.

Calm Storm
There is some logic to it - Knowing the driver type helps you understand under what circumstances the driver will work. For instance, a driver using native code wouldn't work if you can't deploy native code (say in an applet).
Eric Petroelje
A: 

In short, each Type uses a different strategy and works better for different types of implementations. I don't think it was laziness. I think it was to be able to more easily and clearly pick out which Type is best for your particular situation.

Brian T Hannan
+3  A: 

The numbers aren't very informative. I find it more useful to think of it along the lines of:

  • Local API (1,2) vs network protocol (3, 4)
  • Database-independent (odd numbers) vs database-specific (even numbers)

I could never remember the numbers, but when someone said "we use a type-4 driver here", I could ask two yes-no questions to know what they were talking about.

d__
Nice mnemonic .
BalusC
+4  A: 

The types tells something about how the driver actually communicates with the database.

  1. Communicates through ODBC API.
  2. Communicates through DB vendor specific API (i.e. using JNI calls on e.g. a DLL file at Windows).
  3. Communicates through generic network protocol (i.e. using sockets).
  4. Communicates through DB vendor specific network protocol (still with sockets).

In general (just by coincidence), how higher the type number, how better the JDBC driver performs.

BalusC
+2  A: 

I believe it goes back to Sun's original (1997) intro to JDBC:

The JDBC drivers that we are aware of at this time generally fit into one of four categories:

  1. JDBC-ODBC bridge plus ODBC driver: The JavaSoft bridge product provides JDBC access via ODBC drivers. Note that ODBC binary code, and in many cases database client code, must be loaded on each client machine that uses this driver. As a result, this kind of driver is most appropriate on a corporate network where client installations are not a major problem, or for application server code written in Java in a three-tier architecture.

  2. Native-API partly-Java driver: This kind of driver converts JDBC calls into calls on the client API for Oracle, Sybase, Informix, DB2, or other DBMS. Note that, like the bridge driver, this style of driver requires that some binary code be loaded on each client machine.

  3. JDBC-Net pure Java driver: This driver translates JDBC calls into a DBMS-independent net protocol which is then translated to a DBMS protocol by a server. This net server middleware is able to connect its pure Java clients to many different databases. The specific protocol used depends on the vendor. In general, this is the most flexible JDBC alternative. It is likely that all vendors of this solution will provide products suitable for intranet use. In order for these products to also support Internet access, they must handle the additional requirements for security, access through firewalls, and so forth, that the Web imposes.

  4. Native-protocol pure Java driver: This kind of driver converts JDBC calls into the network protocol used by DBMSs directly. This allows a direct call from the client machine to the DBMS server and is an excellent solution for intranet access. Since many of these protocols are proprietary, the database vendors themselves will be the primary source. Several database vendors have these in progress.

The expectation is that eventually driver categories 3 and 4 will be the preferred way to access databases from JDBC. Driver categories 1 and 2 are interim solutions where direct pure Java drivers are not yet available. There are possible variations on categories 1 and 2 (not shown in the table below) that require a connector, but these are generally less desirable solutions. Categories 3 and 4 offer all the advantages of Java, including automatic installation (for example, downloading the JDBC driver with an applet that uses it).


Note that they didn't actually name them Type 1, 2, 3 and 4, but rather JDBC-ODBC bridge plus ODBC driver, Native-API partly-Java driver, JDBC-Net pure Java driver, and Native-protocol pure Java driver. Each name was a mouthful, so people immediately started referring to them by their number instead.

Matthew Flynn