The Layered Architecture of JDBC
Your code never talks to a specific database engine: it programs against the java.sql interfaces, and each vendor ships the Driver that implements them in binary.
jdbc:postgresql://localhost:5432/tienda 0 lines changed in the application layer SQL Injection vs PreparedStatement: The Structural Separation
Concatenating user input into SQL confuses data with executable code. PreparedStatement compiles the query as a fixed tree before the data even exists.
String sql = "SELECT * FROM usuarios "
+ "WHERE email = '" + entrada + "'";
rs = statement.executeQuery(sql); SELECT * FROM usuarios WHERE email = 'facundo@mail.com' String sql = "SELECT * FROM usuarios "
+ "WHERE email = ?";
ps = conn.prepareStatement(sql);
ps.setString(1, entrada); SELECT * FROM usuarios WHERE email = ? → "facundo@mail.com" The ResultSet Cursor: Traversing Records in Memory
ResultSet is not a list loaded into memory: it is a cursor pointing at a buffer that talks to the database row by row via rs.next().
| id | name | price |
|---|---|---|
| 1 | Teclado | 45.0 |
| 2 | Mouse | 20.0 |
| 3 | Monitor | 220.0 |
// rs.next() hasn't been called yet ACID Transactions: The Atomic Transfer Protocol
If a $100 transfer between two accounts is interrupted halfway, the money cannot evaporate: either every change is confirmed with commit, or none is applied with rollback.
conn.setAutoCommit(false); Connection Pools (HikariCP) and the DAO Pattern
Opening a TCP/TLS connection with authentication costs hundreds of milliseconds. A pool like HikariCP keeps connections already open, ready to lend out.
conn.close() doesn't destroy the connection: it returns it to the pool for the next request.