Which DriverManager method is used to establish a database connection?
Answer: B
DriverManager.getConnection() is the standard method that takes URL, username, and password to establish a connection to the database.
Q.302Medium
What does the setAutoCommit(false) method do in JDBC?
Answer: A
setAutoCommit(false) disables automatic commit, allowing multiple statements to be part of single transaction. Manual commit() or rollback() must be called.
Q.303Medium
Which of the following is the correct way to close JDBC resources to prevent resource leaks?
Answer: D
Resources should be closed in reverse order of creation (ResultSet → Statement → Connection), or preferably using try-with-resources which auto-closes resources.
Q.304Medium
What does the PreparedStatement interface provide that Statement does not?
Answer: D
PreparedStatement provides both parameterized queries (preventing SQL injection) and precompilation of SQL statements, resulting in better security and performance compared to Statement.
Q.305Medium
Which exception is thrown when a database operation violates a unique constraint in JDBC?
Answer: D
SQLIntegrityConstraintViolationException is a specific subclass of SQLException that is thrown when integrity constraint violations occur, such as unique constraint violations.
Advertisement
Q.306Medium
What is the correct way to use try-with-resources for JDBC operations?
Answer: A
The try-with-resources statement automatically closes resources implementing AutoCloseable. Since Connection implements AutoCloseable, it will be automatically closed.
Q.307Medium
Which method is used to retrieve metadata about the database in JDBC?
Answer: B
The getDatabaseMetaData() method is called on a Connection object to retrieve DatabaseMetaData information about the database, such as table names, column information, etc.
Q.308Medium
In JDBC, what does the ResultSet.absolute(5) method do?
Answer: B
The absolute(int row) method moves the cursor to the specified row number (1-based indexing). absolute(5) moves the cursor directly to row 5.
Q.309Medium
Which JDBC feature allows multiple SQL statements to be sent to the database in a single round trip?
Answer: B
Batch processing allows multiple SQL statements to be grouped and sent together using addBatch() and executeBatch() methods, improving performance by reducing network overhead.
Q.310Medium
In JDBC, which concurrency type allows modifications to the ResultSet?
Answer: B
CONCUR_UPDATABLE is the ResultSet concurrency type that allows the ResultSet to be updated. CONCUR_READ_ONLY prevents modifications.
Q.311Medium
Which JDBC method allows you to retrieve column information such as column name, type, and size?
Answer: A
ResultSetMetaData interface provides information about the columns returned in a ResultSet, such as getColumnName(), getColumnType(), getColumnCount(), etc. Obtained via rs.getMetaData().
Q.312Medium
Which JDBC method is used to retrieve metadata information about the database?
Answer: A
Connection.getMetaData() returns a DatabaseMetaData object containing information about the database and driver.
Q.313Medium
In a JDBC batch operation, what does executeBatch() return?
Answer: B
executeBatch() returns an int array where each element represents the number of rows affected by each statement in the batch.
Q.314Medium
What is the difference between ResultSet.TYPE_SCROLL_INSENSITIVE and ResultSet.TYPE_SCROLL_SENSITIVE?
Answer: A
TYPE_SCROLL_INSENSITIVE doesn't reflect concurrent database changes, while TYPE_SCROLL_SENSITIVE may reflect such changes.
Q.315Medium
Which JDBC method is used to set an input parameter in a PreparedStatement?
Answer: B
PreparedStatement uses type-specific setter methods like setInt(), setString(), setDate() to bind parameters.
Q.316Medium
What happens when Connection.setAutoCommit(false) is called in JDBC?
Answer: B
Setting autoCommit to false enables manual transaction management where commit() must be explicitly called.
Q.317Medium
In JDBC, what is the purpose of the ResultSetMetaData interface?
Answer: B
ResultSetMetaData provides information about columns, data types, and column properties of a ResultSet.
Q.318Medium
Which JDBC constant specifies read-only access for a ResultSet?
Answer: A
CONCUR_READ_ONLY is the concurrency constant that specifies a read-only ResultSet.
Q.319Medium
What is Connection pooling in JDBC and why is it used?
Answer: B
Connection pooling maintains a pool of reusable connections, reducing the cost of creating new connections repeatedly.
Q.320Medium
In JDBC, what is the purpose of CallableStatement?
Answer: B
CallableStatement is used to call stored procedures and stored functions in the database.