DEV Community

loading...

JDBC in simple

buddhikac96 profile image Buddhika Chathuranga ・2 min read

In this article, I will straightforwardly explain JDBC. Let's get into the topic directly. First, I will get a simple terminology to explain JDBC.

Imagine we are living in a city called City A. We are low on water. City B has a well that is full of water. But our language (City A language) and their language (City B language) are different. So, first of all, we are going to need a language translator. Then we need a road to go to City B. Then we need a vehicle to go to City B. When we send our vehicle to City B, there should be a tank on the vehicle to bring water to City A.

This terminology explains nothing but JDBC application architecture. Imagine there are a Database and a Java application. We need to get data from the database to our Java application. According to the above terminology, our Java application is nothing but the City A, low on water. The database is nothing but the City B, which is rich in water.

Now we need some application that can convert our Java call into a Database understandable call. In the above terminology, this tool is nothing but the language translator. In JDBC terminology, it is the Driver.

When we get the connection, we need a vehicle to send our database request to the Java application database. This vehicle is nothing but Statement Object.

When we send our vehicle to City B, there should be a tank to fill water. In JDBC terminology, this tank is nothing but Result Set. When the vehicle brings back the tank with water from City B, we can carefully unload the water tank from the vehicle. When the statement object brings back the data we want in the result set, we can fetch that data from the Java application.

Now let's try to summarize this.

Components of the JDBC

  1. Driver - Translate Java calls into Database calls
  2. Connection - Create the connection between the java application and the Database
  3. Statement Object - Transport our database query to the database
  4. Result Set - Contains the data received from the database

Using these components, we can create a simple JDBC application. These are the basics steps to follow to create a JDBC application.

Steps to create a JDBC application

  1. Load and register the driver
  2. Establish the connection to the database
  3. Create the statement object
  4. Send and execute the query
  5. Receive and process data
  6. Close the connection

By following the above steps, we can develop a simple JDBC application.

Resources

Discussion

pic
Editor guide
Collapse
braisdom profile image
Braisdom

Refer to the github.com/braisdom/ObjectiveSql for more information