← Back to Java
Java

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.

Question 1
Interview Beginner
Question

What is JDBC?

Answer:

JDBC (Java Database Connectivity) is an API that enables Java applications to connect to and interact with relational databases.

Question 2
Interview Beginner
Question

What is JDBC architecture?

Answer:

JDBC architecture consists of Java applications, JDBC API, DriverManager, JDBC drivers, and the database.

Question 3
Interview Beginner
Question

What are the types of JDBC drivers?

Answer:

The four JDBC driver types are JDBC-ODBC Bridge, Native Driver, Network Protocol Driver, and Thin Driver.

Question 4
Interview Beginner
Question

How do you connect Java to a database?

Answer:

Load the JDBC driver, establish a connection using DriverManager, create a statement, execute queries, and close resources.

Question 5
Interview Beginner
Question

What is DriverManager?

Answer:

DriverManager manages JDBC drivers and establishes database connections.

Question 6
Interview Beginner
Question

What is the Connection interface?

Answer:

Connection represents an active connection to a database and provides methods for transaction management and statement creation.

Question 7
Interview Beginner
Question

What is a Statement?

Answer:

Statement is used to execute static SQL queries against a database.

Question 8
Interview Intermediate
Question

What is the difference between Statement and PreparedStatement?

Answer:

PreparedStatement is precompiled, supports parameters, improves performance, and helps prevent SQL injection.

Question 9
Interview Intermediate
Question

What is CallableStatement?

Answer:

CallableStatement is used to execute stored procedures in a database.

Question 10
Interview Intermediate
Question

What is ResultSet?

Answer:

ResultSet is an object that stores and allows navigation through data returned by a SQL query.

Question 11
Interview Intermediate
Question

What are the types of ResultSet?

Answer:

ResultSet types include TYPE_FORWARD_ONLY, TYPE_SCROLL_INSENSITIVE, and TYPE_SCROLL_SENSITIVE.

Question 12
Interview Intermediate
Question

What is batch processing in JDBC?

Answer:

Batch processing groups multiple SQL statements into a single database call for improved performance.

Question 13
Interview Intermediate
Question

What is transaction management?

Answer:

Transaction management ensures that a set of database operations are executed as a single logical unit.

Question 14
Interview Intermediate
Question

What are commit() and rollback()?

Answer:

commit() permanently saves transaction changes, while rollback() undoes changes since the last commit.

Question 15
Interview Advanced
Question

How can SQL Injection be prevented?

Answer:

SQL Injection can be prevented by using PreparedStatement, parameterized queries, and input validation.

Question 16
Interview Advanced
Question

Which Java language or JDK features are essential when discussing JDBC & Database Connectivity?

Answer:

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.

Question 17
Interview Advanced
Question

How does exception handling typically work around JDBC & Database Connectivity in Java?

Answer:

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.

Question 18
Interview Advanced
Question

What unit-testing approach would you use for JDBC & Database Connectivity?

Answer:

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.

Question 19
Interview Advanced
Question

How do equals/hashCode or identity rules affect JDBC & Database Connectivity?

Answer:

Incorrect equals/hashCode break HashMap/HashSet behavior. If JDBC & Database Connectivity stores objects in collections, explain the contract and mutability pitfalls.

Question 20
Interview Advanced
Question

What memory or GC concern should juniors watch with JDBC & Database Connectivity?

Answer:

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