JDBC | Introduction to Java Database Connectivity

What is JDBC?

What are the different types of JDBC drivers?

  • JDBC-ODBC Bridge Driver
  • Native-API Driver (partially Java driver)
  • Network Protocol Driver (fully Java driver)
  • Thin Driver (fully Java driver).
  • JDBC-ODBC Bridge Driver/Type-1 Driver: There are some databases which provide ODBC driver to connect their databases. Here, ODBC stands for Open Database Connectivity.
  • Native-API driver/Type-2 Driver: Some database vendors provide only Native APIs, written in C/C++ programming languages, in order to access their database.
  • Network Protocol Driver/Type-3 Driver: The Network Protocol Driver uses middleware to convert JDBC calls directly or indirectly into vendor-specific database protocol.
  • Thin Driver/Type-4 Driver: Thin Driver directly communicates with the database. This driver doesn’t require any native database library or middleware server to communicate with the database. Here, the thin driver converts JDBC calls made by Java application into vendor-specific database protocol.

How JDBC works

  • It helps to establish a connection with a data source
  • It allows to send queries and updates statements
  • It helps to fetch the data from the database and process the fetched results.

Why JDBC is needed?

JDBC components:

  1. Driver Manager: Driver Manager is a class which manages all the database drivers. The Driver Manager is used to load the specific database drivers in an application to establish a connection with the database.
  2. Driver: Driver is the interface which manages the communications happening between the application and the database server.
  3. Connection: Connection is an interface which contains methods for contacting the database.
  4. Statement: Statement is an interface that creates an object to submit SQL queries or statements to the database.
  5. Result Set: Result Set contains the results that are retrieved from the database after the execution of SQL statements or queries.
  6. SQL Exception: SQL Exception class is used to handle any of the errors that occur in a database application.

Which Database is best suited for Java?

  1. Oracle
  2. MySQL
  3. PostgreSQL
  4. IBM-DB2
  5. MS-SQL

Advantages of Java Database Connectivity:

  1. JDBC itself creates XML format of data from the database automatically
  2. JDBC supports modules
  3. JDBC provides better security
  4. JDBC completely supports query and stored procedure
  5. JDBC supports both types of processing i.e. Synchronous and Asynchronous processing
  6. JDBC does not require content conversion.




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store