Advanced Java Programming - Old Questions

5. What is JDBC? Discuss different driver types of JDBC.

5 marks | Asked in 2071

Java Database Connectivity (JDBC) is an Application Programming Interface (API) used to connect Java application with Database. JDBC is used to interact with various type of Database such as Oracle, MS Access, My SQL and SQL Server. It allows java program to execute SQL statement and retrieve result from database.

JDBC Driver is a software component that enables java application to interact with the database. There are 4 types of JDBC drivers:

Type 1: JDBC-ODBC Bridge

  • To use a Type 1 driver in a client machine, an ODBC driver should be installed and configured correctly.
  • This type of driver does not directly interact with the database. To interact with database, it needs ODBC driver.
  •  The JDBC-ODBC bridge driver converts JDBC method class into ODBC method calls.
  •  It can be used to connect to any type of the databases.

Type 2: Native –API driver

  • Type 2 drivers are written partially in Java and partially in native code.
  • The Native-API of each database should be installed in the client system before accessing a particular database. So in this way, a Native-API driver is database specific driver.
  • This driver converts JDBC method calls into native calls of the database API.

Type 3: Net Pure Java Driver

  • In a Type 3 driver, the JDBC driver on the client machine uses the socket to communicate with the middleware at the server. The middleware or server acts as a gateway to access the database.
  • The client database access requests are sent through the network to the middleware or server and then the middleware converts the request to the database specific API.
  •  Type-3 drivers are fully written in Java, hence they are portable drivers.

Type 4: Pure Java Driver

  • This driver interact directly with database. It does not require any native database library and middleware server, that is why it is also known as Thin Driver.
  • No client-side or server-side installation.
  • It is fully written in Java language, hence they are portable drivers.