• Post author:
  • Post category:JAVA
  • Post comments:0 Comments

JDBC stands for Java Database Connectivity. It is an application programming interface, API for short.To fully understand the functions of the JDBC, we must first delve into what an API actually is.

API, or application programming interface, are the gears under the hood of our modern world. For example, everything today is at reach for the consumer. One can order pizza online, buy clothes, and even order packages. There is a myriad of options in the modern world. However, this still begs the question. What is an API? The API serves as an internal datalink from one database to another that serves its purpose in transferring information.

JDBC Drivers

The JDBC API is an application programming interface serves as the medium between the client and relational databases. It is a part of the JSE platform, made by Oracle.

Jdbc Drivers

To make use of these drivers, the client must install these adapters on the machine they are using.

There are four types of drivers

  1. JDBC-ODBC bridge driver.
  2. Native-API driver (partially java driver)
  3. Network Protocol driver (fully java driver)
  4. Thin driver (fully java driver)

The primary functions of these drivers allow us to connect to a data source, update and send queries to databases, and retrieve data from the database itself. We will delve into the individual functions of these drivers below. Before we can use the JDBC classes, we must import from the java.sql package.

JDBC-ODBC bridge driver

To use this driver, we must install the ODBC driver on the client machine. This driver allows the client machine to convert JDBC method calls into its own function calls. Databases that provide an ODBC driver can be accessed; however, not all platforms can support this.

Furthermore, there is no support from JDK 8+, which means this driver’s usage is confined to experimental uses and theory.

Native-API driver

A noticeable difference between a Type-1 and Type-2 driver is that the Native-API driver converts JDBC method calls into the native API’s database. This means that there is NO further conversion by the ODBC driver. However, like the Type-1 driver, the libraries in the Type-2 driver must be installed on the client machine just like the ODBC driver. Not all databases provide a client-side library.

Network Protocol driver

Middleware converts the JDBC calls into specific calls. Middleware needs to be configured specifically, so a Type-3 driver should only be used if there are multiple databases.

Thin driver

Contains all the functionalities of Type-2 and Type-3 drivers; however, they are database specific.

Connection to MYSQL

import java.sql.*;
// creates a connection to MYSQL 
public class JDBC
public static void main(String[] args)
public static Connection getCon() throws Exception
// if you are using the local host
String url = "jdbc:mysql://localhost:3306/database"; 
String driver = "com.mysql.jdbc.Driver";
String user = String password =Connection con = DriverManager.getConnection(url,user,password); return con;
catch(Exception e)
return null;

This program allows us to connect to MYSQL, which can be used for a variety of things such as creating tables.

Related Articlehttps://codingsmania.in/exception-in-java/

Leave a Reply