JDBC
30 — JDBC & Databases
Previous: 29 Networking · Next: 31 REST APIs
▶️ pkg11jdbc/jdbc1JdbcOverview.java → jdbc5ConnectionPooling.java
JDBC flow
1DriverManager.getConnection(url, user, pass)2 → Connection3 → PreparedStatement ("SELECT * FROM users WHERE id = ?")4 → setInt(1, id)5 → executeQuery() → ResultSet6 → commit() / rollback()7 → close (try-with-resources)Golden rules
| Rule | Why |
|---|---|
Use PreparedStatement |
SQL injection prevention + plan cache |
| Use connection pool (HikariCP) | Creating connections is expensive |
| Manage transactions explicitly | setAutoCommit(false) when needed |
| Close resources | try-with-resources |
Class order
| # | File | Topic |
|---|---|---|
| 1 | jdbc1JdbcOverview |
JDBC architecture |
| 2 | jdbc2JdbcBasics |
CRUD with PreparedStatement |
| 3 | jdbc3Transactions |
commit / rollback |
| 4 | jdbc4BatchProcessing |
Batch inserts |
| 5 | jdbc5ConnectionPooling |
Pool concepts |
Full guide → JDBC · 16 JDBC, JPA & Hibernate
Next → 31 REST APIs
Source named in this chapter
- jdbc1JdbcOverviewpkg11jdbc/jdbc1JdbcOverview.java