Mastering JDBC

JAVA DATABASE CONNECTIVITY

☕ ⚡ 🗄️

The standard API for connecting Java applications to relational databases.

The Architecture Flow

JDBC acts as a bridge, translating Java commands into database-specific instructions.

Java App
JDBC API &
Driver Manager
Database
(MySQL, Oracle)

The Core Interfaces

Hover over the cards to explore the engine of JDBC.

Connection

Establishes the physical session with the database. It's your secure pipeline.

Statement

The vehicle used to execute static SQL queries and send them down the pipeline.

ResultSet

A virtual table holding the data returned from your database after executing a query.

The 5 Essential Steps

Click each step to simulate writing a JDBC program.

Putting it into Code

// 1. Import SQL package
import java.sql.*;

public class DatabaseLink {
    public static void main(String[] args) throws Exception {
        // 2. Establish Connection
        String url = "jdbc:mysql://localhost:3306/school";
        Connection con = DriverManager.getConnection(url, "root", "pass");

        // 3. Create Statement
        Statement st = con.createStatement();

        // 4. Execute Query & Process ResultSet
        ResultSet rs = st.executeQuery("SELECT name FROM students");
        while(rs.next()) {
            System.out.println(rs.getString("name"));
        }

        // 5. Close
        con.close();
    }
}