What is JDBC in Java?
Fast recall
Quick revision
Core answer
Whether you know JDBC is a standard API with vendor-supplied drivers (abstraction layer).
Thinking JDBC talks to the DB directly rather than through a vendor driver.
Explain JDBC is interfaces + a driver; it decouples app code from the specific database.
Interview-ready guide
Interview answer
A program can use Connection, PreparedStatement, and ResultSet similarly with PostgreSQL and MySQL. A simple parameterized SELECT may transfer easily, but JSON operators, identity syntax, arrays, locking, and error codes do not. JDBC standardizes the Java calling contract rather than all database semantics.
What is JDBC in Java
Direct Answer
JDBC is Java's standard API for connecting to data sources, executing SQL, controlling transactions, and reading results. Vendors provide drivers behind common interfaces. The API makes code structure more portable, but changing databases often requires changes to the JDBC URL, SQL dialect, types, generated keys, and behavior; the same code is not guaranteed to work after only swapping a driver.
Code Example
// JDBC: program against interfaces; the driver implements them
String url = "jdbc:mysql://localhost:3306/shop";
try (Connection con = DriverManager.getConnection(url, "user", "pass");
PreparedStatement ps = con.prepareStatement("SELECT name FROM users WHERE id = ?")) {
ps.setInt(1, 42);
try (ResultSet rs = ps.executeQuery()) {
if (rs.next()) System.out.println(rs.getString("name"));
}
}
// Connection, PreparedStatement, ResultSet are JDBC interfaces;
// the MySQL driver provides the concrete classes.
Common Mistakes & Pitfalls
- Thinking JDBC talks to the DB directly: it calls a vendor driver that does the talking.
- Missing the driver dependency: no driver JAR →
No suitable drivererror. - Not closing resources: leaking
Connection/ResultSetexhausts the pool. - Confusing JDBC with JPA: JDBC is the low-level API; JPA/Hibernate sit on top of it.
Check your understanding
Answer these without looking back at the article.
- What is JDBC and why does it exist? It provides a standard Java API for connecting to relational databases, executing SQL, and processing results without vendor-specific code.
- What are the main components of the JDBC API?
- What are the steps to execute a SQL query using JDBC?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.