Java Programming — JDBC
Java OOP, collections, multithreading
100 Questions 10 Topics Take Test
Advertisement
Showing 1–10 of 100 questions in JDBC
Q.1 Hard JDBC
In JDBC metadata operations, which method is used to retrieve information about table structure, column names, and their data types?
A getDatabaseMetaData()
B getMetaData() on ResultSet
C getColumnCount() and getColumnName()
D Both B and C together
Correct Answer:  D. Both B and C together
EXPLANATION

getMetaData() on ResultSet returns ResultSetMetaData which provides column information. getColumnCount() and getColumnName() are methods of ResultSetMetaData used to retrieve structure details.

Take Test
Q.2 Hard JDBC
A Java application requires connection pooling to handle 1000+ concurrent database requests efficiently. Which JDBC component should be implemented?
A Direct DriverManager.getConnection() calls
B DataSource interface with connection pool implementation like HikariCP or C3P0
C Creating new Connection for each request manually
D Using Statement caching only
Correct Answer:  B. DataSource interface with connection pool implementation like HikariCP or C3P0
EXPLANATION

DataSource with connection pooling frameworks (HikariCP, C3P0) efficiently manages connections by reusing them, reducing overhead. Direct getConnection() calls create new connections each time, which is inefficient for high concurrency.

Take Test
Q.3 Medium JDBC
In JDBC 2024-25, which exception is thrown when attempting to use a closed Connection object?
A SQLException
B SQLClientInfoException
C SQLInvalidAuthorizationSpecException
D SQLNonTransientConnectionException
Correct Answer:  A. SQLException
EXPLANATION

A SQLException (specifically a SQLNonTransientConnectionException as a subclass) is thrown when operations are attempted on a closed Connection. SQLException is the general exception for database access errors.

Take Test
Q.4 Medium JDBC
When using ResultSet in JDBC, which cursor type allows bidirectional movement through rows but does not reflect database changes?
A TYPE_FORWARD_ONLY
B TYPE_SCROLL_INSENSITIVE
C TYPE_SCROLL_SENSITIVE
D TYPE_DYNAMIC
Correct Answer:  B. TYPE_SCROLL_INSENSITIVE
EXPLANATION

TYPE_SCROLL_INSENSITIVE allows movement in both directions (previous, next, absolute) but doesn't reflect changes made to the database after the ResultSet was created. TYPE_SCROLL_SENSITIVE would reflect changes.

Take Test
Q.5 Medium JDBC
A developer needs to execute the same SQL query multiple times with different parameters. Which JDBC feature should be used to optimize performance?
A Statement with loop execution
B PreparedStatement with parameterized queries
C CallableStatement for all queries
D Multiple Connection objects
Correct Answer:  B. PreparedStatement with parameterized queries
EXPLANATION

PreparedStatement pre-compiles the query and allows parameter binding, reducing overhead and improving performance for repeated executions. It also prevents SQL injection.

Take Test
Advertisement
Q.6 Easy JDBC
In a JDBC application, which interface is responsible for executing SQL queries and returning ResultSet objects?
A Statement
B Connection
C Driver
D DataSource
Correct Answer:  A. Statement
EXPLANATION

The Statement interface is used to execute SQL queries. Connection creates the statement, Driver manages connections, and DataSource provides connection pooling, but Statement is the actual executor.

Take Test
Q.7 Hard JDBC
In a JDBC application using batch updates, what happens if one statement in the batch fails?
A All statements are executed, and failure is reported
B All statements are rolled back automatically
C Only failed statement is skipped
D Behavior depends on database configuration
Correct Answer:  D. Behavior depends on database configuration
EXPLANATION

executeBatch() behavior on failure varies by database and driver. BatchUpdateException is thrown, containing update counts for each statement. Explicit transaction control is recommended.

Take Test
Q.8 Medium JDBC
Which JDBC feature allows monitoring of database metadata like table structure and column information?
A DatabaseMetaData interface
B ResultSetMetaData interface
C ParameterMetaData interface
D StatementMetaData interface
Correct Answer:  A. DatabaseMetaData interface
EXPLANATION

DatabaseMetaData (obtained from Connection.getMetaData()) provides information about the entire database like tables, columns, keys, and supported features.

Take Test
Q.9 Hard JDBC
A query execution takes 5 seconds consistently. Which JDBC optimization technique should NOT be used for this scenario?
A Connection pooling
B Batch processing for multiple inserts
C Using indexes on frequently queried columns
D Increasing setFetchSize() value
Correct Answer:  D. Increasing setFetchSize() value
EXPLANATION

If query execution itself is slow (5 seconds), the bottleneck is in database operations, not data transfer. Increasing setFetchSize() only optimizes data retrieval, not query execution.

Take Test
Q.10 Medium JDBC
What is the correct way to handle resource management in JDBC with Java 7+?
A try-catch-finally blocks with explicit close()
B try-with-resources statement (try-with parentheses)
C Using finally blocks only
D Automatic garbage collection handles it
Correct Answer:  B. try-with-resources statement (try-with parentheses)
EXPLANATION

try-with-resources automatically closes AutoCloseable resources (Connection, Statement, ResultSet), preventing connection leaks elegantly.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips