JDBC Basics
Fast recall
Quick revision
Core answer
Whether you understand the core JDBC workflow (load driver, get connection, create statement, execute query, process results, close resources) and the difference between Statement, PreparedStatement, and CallableStatement.
Using Statement instead of PreparedStatement for parameterized queries, leading to SQL injection, or forgetting to close Connection, Statement, and ResultSet.
Explain how PreparedStatement pre-compiles SQL for performance, how connection pooling works, and how try-with-resources prevents resource leaks in JDBC.
Interview-ready guide
Interview answer
A Java program can prepare SELECT name FROM users WHERE id = ?, bind an id, execute the statement, and read a ResultSet through the same JDBC interfaces on supported databases. The driver performs the vendor-specific work. Migrating from PostgreSQL to MySQL may still change schema types, generated keys, queries, and transaction behavior. JDBC avoids an entirely different Java client API per database; it does not promise a driver-only migration.
JDBC Basics
Direct Answer
JDBC is Java's standard API for connecting to data sources, executing SQL, managing transactions, and reading results. Database vendors provide drivers behind common interfaces such as Connection, Statement, PreparedStatement, and ResultSet. This gives Java code a consistent programming model, but SQL dialects and database behavior can still require changes when switching vendors.
Common Mistakes & Pitfalls
Using Statement instead of PreparedStatement for parameterized queries, leading to SQL injection, or forgetting to close Connection, Statement, and ResultSet.
Check your understanding
Answer these without looking back at the article.
- What is the difference between Statement and PreparedStatement in JDBC?
- How does JDBC connection pooling work and why is it necessary?
- What is SQL injection and how does PreparedStatement prevent it?
- How do you handle transactions in JDBC using commit and rollback?
- What is the role of the JDBC Driver and DriverManager?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.