JDBC API Components — Connection, Statement, ResultSet
Fast recall
Quick revision
Core answer
Whether you can name the core JDBC components and how they fit together.
Listing classes without explaining the connection→statement→resultset flow.
Group them by role and mention DataSource (pooled) as the modern way to get connections.
Interview-ready guide
Interview answer
For example, try (Connection c=dataSource.getConnection(); PreparedStatement ps=c.prepareStatement("select name from customer where id=?")) binds id, calls executeQuery(), then iterates the ResultSet. Closing a pooled Connection normally returns the logical connection to its pool; closing a nonpooled connection closes the physical database connection.
JDBC API Components — Connection, Statement, ResultSet
Direct Answer
JDBC centers on Driver/DriverManager or DataSource for obtaining connections, Connection for a database session and transaction boundary, Statement/PreparedStatement/CallableStatement for executing SQL, ResultSet for reading tabular results, and SQLException/metadata types for errors and capabilities. DataSource is an abstraction for connection acquisition; it may be pooled, managed, or create physical connections, so pooling is not guaranteed by the interface.
Code Example
DataSource ds = ...; // entry point (pooled)
try (Connection con = ds.getConnection(); // Connection
PreparedStatement ps = // PreparedStatement
con.prepareStatement("SELECT id, name FROM users WHERE active = ?")) {
ps.setBoolean(1, true);
try (ResultSet rs = ps.executeQuery()) { // ResultSet
while (rs.next()) {
System.out.println(rs.getInt("id") + ": " + rs.getString("name"));
}
}
} catch (SQLException e) { // SQLException
throw new RuntimeException("query failed", e);
}
Common Mistakes & Pitfalls
Listing classes without explaining the connection→statement→resultset flow.
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 is JDBC and what is its role in Java?
- 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.