What is JDBC

What is JDBC ?

  • JDBC stands for java database connectivity.
  • JDBC is an API that help us to achieve connectivity between java program and database
  •  If we have web application and if we have database then web application must interact with database to read or modifies a data.
  • JDBC is help us to Achieve this functionality.
  •  TO interact with any database JDBC must needed. screenshot_1

Advantage of JDBC

• Since JDBC API built upon java so it inherits advantage of java
• JDBC is Database independent
• Using JDBC we can interact with multiple database.
• We can achieve high Performance using JDBC with the help of
o Prepare statement
o Callable statement
• JDBC support Stored Procedure.

JDBC Driver

Necessary step to work with JDBC

  1.  Load driver
  2.  Get the db connection via driver
  3.  Issue sql query via connection
  4.  Process the result return by sql query
  5.  Close all JDBC object

JDBC is an API(Collection of Packages)
JDBC uses Driver to interact with databasedriver

What is Driver ?
  • Driver is additional software component require by JDBC to
    interact with database.
  • Driver are Provided by Database vendor and they are Database
  •  Driver is a concrete class present in jar file
  • Driver help us to establish database connection, transfer database
    query and result between java program and database.
How to load DriverThere are two ways to load driver
First way:

import java.sql.DriverManager;
import com.mysql.jdbc.Driver;

Driver ref=new Driver();

Second way:

another way to load driver using

this approach is most common approach to load driver and
this approach automatically register driver class


Types of Driver:

There are Four types of Driver

  1. Type-1 JDBC ODBC Bridge
  2. Type-2 Native API
  3. Type-3 Network protocol
  4. Type-4 Native Protocol
  • Type-1 and Type-2 require Client side installation so it is less efficient.
  • Type-3 and Type-4 Driver develop using java so it is efficient.
  • Type-3 driver support More database.
  • Type-4 Driver give high performance because it is directly connected with database
Step to Configure Driver:
1. Configure project build path

  • Download mysql zip file and Extract it
  • go to eclipse
  • right click on project
  • select build path
  • choose option “Add External Archive” and Select mysql connector jar file
What is Jar file ?
  • It is collection of ‘ .class ‘ + other necessary
    resources(text,xml etc)
  •  Jar file help us to transfer the java application from
    one place to another place.