In JDBC 2024-25, which exception is thrown when attempting to use a closed Connection object?
ASQLException
BSQLClientInfoException
CSQLInvalidAuthorizationSpecException
DSQLNonTransientConnectionException
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.
When using ResultSet in JDBC, which cursor type allows bidirectional movement through rows but does not reflect database changes?
ATYPE_FORWARD_ONLY
BTYPE_SCROLL_INSENSITIVE
CTYPE_SCROLL_SENSITIVE
DTYPE_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.
A developer needs to execute the same SQL query multiple times with different parameters. Which JDBC feature should be used to optimize performance?
AStatement with loop execution
BPreparedStatement with parameterized queries
CCallableStatement for all queries
DMultiple 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.
Which JDBC feature allows monitoring of database metadata like table structure and column information?
ADatabaseMetaData interface
BResultSetMetaData interface
CParameterMetaData interface
DStatementMetaData 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.
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.