A developer needs to execute a query that returns multiple result sets. Which Statement type should be used?
Answer: C
The execute() method returns a boolean and can handle multiple result sets via getResultSet(), getUpdateCount(), and getMoreResults() methods.
Q.82Medium
What is the purpose of Connection pooling in JDBC applications?
Answer: B
Connection pooling maintains a pool of reusable connections, reducing the overhead of creating new connections for each request, improving application performance.
Q.83Medium
Consider a scenario where a developer uses getConnection() without closing it. What is the potential impact?
Answer: B
Unclosed connections remain allocated and unavailable for other operations, eventually exhausting the connection pool and causing connection exhaustion errors.
Q.84Easy
Which exception is thrown when a JDBC driver is not found in the classpath?
Answer: B
When Class.forName() cannot locate the driver class, it throws ClassNotFoundException, indicating the driver JAR is not in the classpath.
Q.85Medium
What does the setMaxRows() method in Statement do?
Answer: A
setMaxRows() limits the number of rows returned by executeQuery(), useful for memory management when dealing with large result sets.
Advertisement
Q.86Medium
In a multi-threaded JDBC application, what should be the approach for Connection object usage?
Answer: B
Connection objects are not thread-safe. Each thread should obtain its own Connection from a thread-safe connection pool to avoid race conditions.
Q.87Medium
Which method in ResultSet is used to check if a column value is NULL?
Answer: B
wasNull() returns true if the last retrieved value was NULL in the database, checked after calling a getter method like getString() or getInt().
Q.88Hard
A developer wants to retrieve data from a stored procedure that returns multiple result sets and output parameters. Which approach is correct?
Answer: C
CallableStatement is specifically designed for stored procedures, supporting registerOutParameter() for output parameters and getMoreResults() for multiple result sets.
Q.89Easy
What is the difference between commit() and rollback() in JDBC transactions?
Answer: A
commit() permanently saves all changes made during the transaction, while rollback() discards all changes and reverts to the previous state.
Q.90Medium
In JDBC 2024-25, which data type mapping is incorrect for Java to SQL?
Answer: D
byte[] should map to BLOB (Binary Large Object), not CHAR. CHAR is for single character types.
Q.91Medium
What is the correct way to handle resource management in JDBC with Java 7+?
A query execution takes 5 seconds consistently. Which JDBC optimization technique should NOT be used for this scenario?
Answer: D
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.
Q.93Medium
Which JDBC feature allows monitoring of database metadata like table structure and column information?
Answer: A
DatabaseMetaData (obtained from Connection.getMetaData()) provides information about the entire database like tables, columns, keys, and supported features.
Q.94Hard
In a JDBC application using batch updates, what happens if one statement in the batch fails?
Answer: D
executeBatch() behavior on failure varies by database and driver. BatchUpdateException is thrown, containing update counts for each statement. Explicit transaction control is recommended.
Q.95Easy
In a JDBC application, which interface is responsible for executing SQL queries and returning ResultSet objects?
Answer: A
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.
Q.96Medium
A developer needs to execute the same SQL query multiple times with different parameters. Which JDBC feature should be used to optimize performance?
Answer: B
PreparedStatement pre-compiles the query and allows parameter binding, reducing overhead and improving performance for repeated executions. It also prevents SQL injection.
Q.97Medium
When using ResultSet in JDBC, which cursor type allows bidirectional movement through rows but does not reflect database changes?
Answer: B
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.
Q.98Medium
In JDBC 2024-25, which exception is thrown when attempting to use a closed Connection object?
Answer: A
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.
Q.99Hard
A Java application requires connection pooling to handle 1000+ concurrent database requests efficiently. Which JDBC component should be implemented?
Answer: B
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.
Q.100Hard
In JDBC metadata operations, which method is used to retrieve information about table structure, column names, and their data types?
Answer: D
getMetaData() on ResultSet returns ResultSetMetaData which provides column information. getColumnCount() and getColumnName() are methods of ResultSetMetaData used to retrieve structure details.