Nearby lessons
1 of 37JDBC - Introduction
- Where JDBC fits in the Java world (Core vs Advanced Java)
- JDBC in the simplest words — with a real-life story
- Storage areas: temporary vs permanent
- Why we use a database and not files
- The evolution: C/C++ libraries → ODBC → JDBC
- The difference between JDBC and ODBC
Introduction is a fundamental part of database programming with JDBC. This lesson explains First, Understand Core vs Advanced Java, JDBC in the Simplest Words and Storage Areas — Where Does Data Live? with complete, runnable code examples, clear step-by-step explanations, and common mistakes to avoid with exam-style MCQs at the end.
First, Understand Core vs Advanced Java
With Core Java knowledge, we can build stand-alone applications — programs that run on one single machine. Examples: a calculator, MS Word.
With Advanced Java, we build web applications — programs that provide services over the internet. Examples: a mail service, a social media site, an online video site.
In Java, web applications are built using three main technologies, and each has its own job:
| Technology | Job in simple words |
|---|---|
| JSP | Shows things to the user (the view) — login page, inbox page, result page. |
| Servlet | Does the thinking (the logic) — verify user, process data, talk to the database. |
| JDBC | Talks to the database — sends SQL and brings back results. |
So the flow is: JSP shows the page → Servlet does the logic → JDBC talks to the database. JDBC is the bridge between your Java code and the database.
Java has three editions, and each serves a different purpose:
| Edition | Full name | Used for |
|---|---|---|
| JSE / J2SE | Java Standard Edition | Stand-alone (desktop) applications |
| JEE / J2EE | Java Enterprise Edition | Web / enterprise applications |
| JME / J2ME | Java Micro Edition | Mobile / embedded devices |
JDBC in the Simplest Words
The classic material explains JDBC with a beautiful real-life story. Imagine a customer in one city wants to buy gold from a jewellery shop in another city. Four things are needed:
| Story character | JDBC part | What it does |
|---|---|---|
| Translator | Driver | Converts Java calls into database calls, and database calls back into Java. Without a translator, the two cannot understand each other. |
| Road | Connection | The path on which the Java application and the database talk to each other. |
| Vehicle | Statement | Carries the SQL query to the database and brings the results back. |
| Gold box | ResultSet | Holds the results returned by the SQL query. |
Remember this story and you will never forget what Driver, Connection, Statement and ResultSet do.
Storage Areas — Where Does Data Live?
Every application needs to store data — customer information, billing details, call records. Java gives us two kinds of storage areas:
| Type | Meaning | Examples |
|---|---|---|
| Temporary storage | Data stays only while the program runs | JVM memory: heap, stack, method area |
| Permanent (persistent) storage | Data stays even after the program closes | File systems, databases, data warehouses |
Temporary storage is cleared automatically when the JVM shuts down. Permanent storage keeps the data safe for later.
File Systems vs Databases
The simplest permanent storage is the file system (files on your computer). But files have serious limitations:
| Problem with file systems | Simple words |
|---|---|
| Cannot store huge data | Files get slow and messy with lots of data |
| No query language | Searching and updating data by writing code is very complex |
| No security | Anyone can read the file |
| No duplicate prevention | The same data can be saved twice → data inconsistency |
Databases solve all these problems:
- They can store huge amounts of information.
- Every database has a query language (SQL) — so operations are easy.
- Access needs a username and password — so data is secure.
- Data is stored in tables with constraints (like primary key, unique key) — so duplicate data is prevented.
But even databases have limits: they cannot hold terabytes of data, and they handle only structured (table) data — not videos, audio or images comfortably. For that, big companies move to Big Data technologies and data warehouses.
What is JDBC?
JDBC (Java Database Connectivity) is a technology that lets a Java application communicate with any database.
- JDBC is part of the Java Standard Edition.
- JDBC is a specification defined by Sun Microsystems (now Oracle) and implemented by database vendors (Oracle, MySQL, PostgreSQL...). The vendor's implementation is called Driver software.
JDBC features worth remembering:
- Database independent — write the application once, use it with any database.
- Platform independent — JDBC drivers are written in Java, so they run on any operating system.
- Easy CRUD — Create (Insert), Retrieve (Select), Update, Delete are all easy with JDBC.
- Complex operations too — joins, stored procedures, and more.
JDBC versions and their Java versions:
| JDBC version | Part of Java version |
|---|---|
| JDBC 3.0 | J2SE 1.4 |
| JDBC 4.0 | Java SE 6 |
| JDBC 4.1 | Java SE 7 |
| JDBC 4.2 | Java SE 8 |
- JDBC is part of Java SE and is the bridge between Java code and a database.
- JSP shows pages, Servlets do logic, JDBC talks to the database.
- Driver = translator, Connection = road, Statement = vehicle, ResultSet = gold box.
- Permanent storage = files and databases; databases beat files on size, querying, security and consistency.
- Evolution: database libraries → ODBC (Windows only) → JDBC (any platform).
- JDBC is database independent and platform independent; JDBC 4.0+ auto-loads the driver.