JDBC & Database Connectivity Interview Questions
Connections, statements, prepared statements, transactions, and SQL injection prevention.
- 20Questions with answers
- 3Difficulty levels
Questions (20)
Browse beginner, intermediate, and advanced questions with answers — hide them when you want to self-test.
What is JDBC?
JDBC (Java Database Connectivity) is an API that enables Java applications to connect to and interact with relational databases.
What is JDBC architecture?
JDBC architecture consists of Java applications, JDBC API, DriverManager, JDBC drivers, and the database.
What are the types of JDBC drivers?
The four JDBC driver types are JDBC-ODBC Bridge, Native Driver, Network Protocol Driver, and Thin Driver.
How do you connect Java to a database?
Load the JDBC driver, establish a connection using DriverManager, create a statement, execute queries, and close resources.
What is DriverManager?
DriverManager manages JDBC drivers and establishes database connections.
What is the Connection interface?
Connection represents an active connection to a database and provides methods for transaction management and statement creation.
What is a Statement?
Statement is used to execute static SQL queries against a database.
What is the difference between Statement and PreparedStatement?
PreparedStatement is precompiled, supports parameters, improves performance, and helps prevent SQL injection.
What is CallableStatement?
CallableStatement is used to execute stored procedures in a database.
What is ResultSet?
ResultSet is an object that stores and allows navigation through data returned by a SQL query.
What are the types of ResultSet?
ResultSet types include TYPE_FORWARD_ONLY, TYPE_SCROLL_INSENSITIVE, and TYPE_SCROLL_SENSITIVE.
What is batch processing in JDBC?
Batch processing groups multiple SQL statements into a single database call for improved performance.
What is transaction management?
Transaction management ensures that a set of database operations are executed as a single logical unit.
What are commit() and rollback()?
commit() permanently saves transaction changes, while rollback() undoes changes since the last commit.
How can SQL Injection be prevented?
SQL Injection can be prevented by using PreparedStatement, parameterized queries, and input validation.
Which Java language or JDK features are essential when discussing JDBC & Database Connectivity?
Name concrete APIs (collections, concurrency, streams, annotations) tied to JDBC & Database Connectivity. Interviewers want syntax-level clarity plus when you would reach for each feature in production.
How does exception handling typically work around JDBC & Database Connectivity in Java?
Prefer specific checked/unchecked exceptions, wrap lower-level failures with context, and avoid empty catch blocks. For JDBC & Database Connectivity, decide what is recoverable vs fatal to the request thread.
What unit-testing approach would you use for JDBC & Database Connectivity?
JUnit 5 with Arrange-Act-Assert, Mockito for collaborators, and parameterized tests for edge cases. Keep JDBC & Database Connectivity logic pure where possible so tests stay fast.
How do equals/hashCode or identity rules affect JDBC & Database Connectivity?
Incorrect equals/hashCode break HashMap/HashSet behavior. If JDBC & Database Connectivity stores objects in collections, explain the contract and mutability pitfalls.
What memory or GC concern should juniors watch with JDBC & Database Connectivity?
Retain only needed references, prefer streaming for large datasets, and avoid accidental caches. Relate leaks or GC pressure to a concrete JDBC & Database Connectivity scenario.
Practice with AI mock interviews
Run Java mock interviews with AI follow-ups, instant feedback, and analytics on AiLx.
Free to start · No credit card required