JDBC Environment Setup

Now let us do discuss out various types of drivers in JDBC. So basically there are 4 types of standard drivers listed below:

Now, you must be wondering about they are their point do come out which drivers to be used. The solution to this is as simple as we need to use the driver as per accordance with the database with which we are interacting. 

Note: Drivers to be used are directly propionate to which kind of database with which we are dealing.

Drivers are mentioned in the tabular format below corresponding to the database which is as follows:

Database Driver name 
MySQL com.mysql.jdbc.Driver

Now you must be wondering out from where these listed drivers are to be imported. So in order to import the drivers, you need to download a JAR file from the web. Considering the most frequently used database namely MySQL you need to download a JAR file named ‘mysql.connector‘ and so on it goes for other databases.

Note: It is not an essential step as different IDE’s possesses different traits. In some IDE these connectors are inbuilt such as NetBeans while in Eclipse you need to import this JAR file as discussed above by simply downloading corresponding JAR file from the internet and load in the project. 

If you do not know how to import JAR files to libraries in java IDE, first go through this step.

JDBC Tutorial

JDBC stands for Java Database Connectivity. JDBC is a Java API or tool used in Java applications to interact with the database. It is a specification from Sun Microsystems that provides APIs for Java applications to communicate with different databases. Interfaces and Classes for JDBC API comes under java.sql package. In this Java JDBC tutorial, we will be learning about what is Java Database Connectivity with suitable example.

In the present world, where we mostly deal with websites and databases it is as if they matter the most but if we closely look over it is data that matters the most. If we look closer that all developers are revolving and working over the web and mobile technologies but what remains the same is the data.

Hence, there is an urgency to figure out how data is being handled for which this concept comes into play.

Let us do have an overview of why do we need this term which can be better interpreted with the image provided below.

Why do we need to learn advanced java?

As we are well versed with all the concepts of Core Java now comes the time to build projects that will results out in building an application as a final product.  So if we do are only aware of core java we can only build applications that can be run on the machine where the components of it are stored(in simpler words one can say where all the codes are written). These types of applications are known as standalone applications.

Note: Standalone applications being one of two types of applications in the programming world only holds for 5% of the applications in the real world.  

Hence, the scope is very constricted if we only do build standalone applications resulting out in the very little scope of development and scalability which gives birth to advance java which in turn gives birth to 3 components primarily namely JSP, Servlets, and JDBC in order to make the applications run on multiple machines. With the evolution of these 3 components, it removes the constraint of running only a single machine as it was impractical to users in the real-world application is made but forcing users to install then use them. Now, these types of applications are known as web applications that are the applications providing the services to the end-users without installing them. These applications are known as web applications which are not standalone applications.

Now you must be wondering what is JSP and Servlet and how JDBC is interrelated with them. For the time being, just focus only on JDBC in order to get started with what exactly it is and how to use it by referring to the image depicted below as follows:

Note: Conclusion drawn from Image is as follows:

  • JSP stands for Java Server Pages where these pages are considered as View Components as Presentation logic.
  • Servlet is meant for internal processing going on such as reading, fetching values from the database, comparison, etc in the backend as Processing Logic in our process servlet. Servlets do also contain java classes for this background processing for processing logic.
  • JDBC is meant for Connectivity of Java Application in servlets as discussed to our Database.

Similar Reads

What is JDBC?

Let us try to discuss this from scratch till now in the java domain we were simply writing codes(programming) and interacting with the database. Have you ever wonder imagining how internally our program can be linked to a database giving it enormous power to make projects and applications out of our program. Yes, it is possible with the help of this mechanism. Let us discuss in a real-world scenario which later on we will be mapping with technical terms to get an absolute technical understanding of the same with a pictorial representation....

Interfaces and Classes of JDBC API

Some popular interfaces of JDBC API are listed below:...

JDBC Architecture

...

JDBC Environment Setup

Now let us do discuss out various types of drivers in JDBC. So basically there are 4 types of standard drivers listed below:...

Steps to connect JDBC

There are basically seven steps to get your java application connected to deal with the database. Here database could be structured or non-structured, we have to deal accordingly for the same which will be clear by the end of sequential steps execution. In generic mostly we deal with either MySQL or Oracle database as far it is concerned for our java application. Here we will be dealing out with the MySQL database for our java application wherein processing we just have to execute these listed steps below in sequential order to connect JDBC which is as follows:...

Implementation (Working of JDBC)

Suppose the database with which we want to deal is MySQL. So first we need to import the package, for SQL database it is namely ‘java.sql.*‘. Now as per IDE(we need to load its corresponding JAR file in our project in IDE where JAR is manually supposed to be inserted in the IDE, taking ‘eclipse IDE‘ for reference as an IDE in order to illustrate the same in the below example. By far we are done with importing the JAR to our project. Now in order to load the driver, we will be using forName() method by writing “com.mysql.driver_name” which belongs to class ‘class‘...