Close
All

What is JDBC – Java Database Connectivity

What is JDBC – Java Database Connectivity

JDBC supports different types of drivers, each with its own features and characteristics. These drivers define how JDBC communicates with the underlying database.

  • Type 1: JDBC-ODBC bridge driver: This driver acts as a bridge between the JDBC API and the ODBC API. It requires the installation of ODBC drivers and performs translation between JDBC calls and ODBC calls.
  • Type 2: Native-API/partly Java driver: This driver communicates directly with the database using native API calls. It provides better performance than the Type 1 driver but requires database-specific client libraries to be installed.
  • Type 3: Network Protocol driver: This driver communicates with a middle-tier server that acts as a gateway between the application and the database. It provides network transparency and can work with any database that has a corresponding server-side component.
  • Type 4: Native-Protocol driver: This driver communicates directly with the database using a database-specific protocol. It offers the best performance and is purely written in Java, making it platform-independent.

Using JDBC with Databases

To use JDBC with a database, the first step is to establish a connection. This involves providing the necessary connection parameters such as the database URL, username, and password. Once the connection is established, SQL queries can be executed using the Statement or PreparedStatement objects.

Leave a Reply

Your email address will not be published. Required fields are marked *