Rows and columns, like a spreadsheet — e.g. a books table.
A column (or set of columns) that uniquely identifies each row.
A column referencing another table's primary key — models relationships between tables.
| SQL statement | Purpose |
|---|---|
SELECT * FROM books | retrieve all rows/columns |
SELECT title FROM books WHERE year > 2020 | filter with WHERE |
INSERT INTO books VALUES (...) | add a new row |
UPDATE books SET price = 20 WHERE id = 1 | modify existing rows |
DELETE FROM books WHERE id = 1 | remove rows |
Precompiled SQL logic saved inside the database, callable from Java with CallableStatement — centralizes business logic and can improve performance.
| Connection / Statement | Purpose |
|---|---|
DriverManager.getConnection(url) | opens a connection to the database |
conn.createStatement() | creates a basic SQL statement object |
conn.prepareStatement(sql) | creates a parameterized statement |
stmt.executeQuery(sql) | runs a SELECT, returns a ResultSet |
stmt.executeUpdate(sql) | runs INSERT/UPDATE/DELETE, returns rows affected |
| ResultSet | Purpose |
|---|---|
next() | advances to the next row; false when done |
getString(col)/getInt(col)/getDouble(col) | reads a typed column value |
close() | releases database resources |