In JDBC metadata operations, which method is used to retrieve information about table structure, column names, and their data types?
AgetDatabaseMetaData()
BgetMetaData() on ResultSet
CgetColumnCount() and getColumnName()
DBoth 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.
A Java application requires connection pooling to handle 1000+ concurrent database requests efficiently. Which JDBC component should be implemented?
ADirect DriverManager.getConnection() calls
BDataSource interface with connection pool implementation like HikariCP or C3P0
CCreating new Connection for each request manually
DUsing 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.
In a JDBC application using batch updates, what happens if one statement in the batch fails?
AAll statements are executed, and failure is reported
BAll statements are rolled back automatically
COnly failed statement is skipped
DBehavior 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.
A query execution takes 5 seconds consistently. Which JDBC optimization technique should NOT be used for this scenario?
AConnection pooling
BBatch processing for multiple inserts
CUsing indexes on frequently queried columns
DIncreasing 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.
A developer wants to retrieve data from a stored procedure that returns multiple result sets and output parameters. Which approach is correct?
AUse Statement with executeQuery()
BUse PreparedStatement with execute()
CUse CallableStatement with registerOutParameter() and execute()
DUse PreparedStatement with setFetchSize()
Correct Answer:
C. Use CallableStatement with registerOutParameter() and execute()
EXPLANATION
CallableStatement is specifically designed for stored procedures, supporting registerOutParameter() for output parameters and getMoreResults() for multiple result sets.