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.
Consider a scenario where a developer uses getConnection() without closing it. What is the potential impact?
ADatabase performance remains unaffected
BConnection leak occurs, exhausting available database connections
CAutomatic rollback happens
DQuery execution becomes slower temporarily
Correct Answer:
B. Connection leak occurs, exhausting available database connections
EXPLANATION
Unclosed connections remain allocated and unavailable for other operations, eventually exhausting the connection pool and causing connection exhaustion errors.
What is the purpose of Connection pooling in JDBC applications?
ATo store query results temporarily
BTo reuse database connections instead of creating new ones each time
CTo encrypt database connections
DTo monitor database performance
Correct Answer:
B. To reuse database connections instead of creating new ones each time
EXPLANATION
Connection pooling maintains a pool of reusable connections, reducing the overhead of creating new connections for each request, improving application performance.