What is the difference between update() and updateRow() methods in ResultSet?
Answer: A
update*() methods (like updateInt(), updateString()) modify individual column values in the current row, while updateRow() commits all these changes to the database.
Q.622Medium
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.623Medium
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.624Hard
A developer wants to prevent SQL injection attacks while executing dynamic queries. Which approach is most secure?
Answer: B
PreparedStatement with parameterized queries is the most secure approach as it separates SQL logic from data. The database treats parameters as data, not executable code, preventing SQL injection.
Q.625Hard
What is the default transaction isolation level in JDBC when autocommit is disabled?
Answer: D
The default isolation level depends on the specific database and JDBC driver configuration. Different databases have different defaults (MySQL is REPEATABLE_READ, Oracle is READ_COMMITTED).
Advertisement
Q.626Hard
Which method is used to check if a CallableStatement has a return value from a stored procedure?
Answer: B
The wasNull() method checks if the last value retrieved from a CallableStatement was NULL. To get the return value, you typically use getInt(), getString(), etc., and then check wasNull().
Q.627Easy
What happens when you call rs.next() on a ResultSet after the last row?
Answer: B
The next() method returns false when there are no more rows available. It does not throw an exception or loop back; it simply indicates that there are no additional rows to traverse.
Q.628Hard
A batch update operation fails partially. How can you identify which statements failed in the batch?
Answer: B
executeBatch() returns an int array where each element represents the update count for the corresponding statement. A value of -3 (Statement.EXECUTE_FAILED) indicates failure for that statement.
Q.629Medium
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.630Hard
In JDBC, what is the purpose of using a SavePoint in a transaction?
Answer: B
A SavePoint allows you to roll back part of a transaction without rolling back the entire transaction. You can create nested transactions by setting multiple savepoints and rolling back to specific ones.
Q.631Easy
Which interface in JDBC is used to execute a single SQL statement and return a ResultSet?
Answer: A
Statement interface is used to execute simple SQL queries without parameters and return results as ResultSet.
Q.632Easy
What is the primary advantage of using PreparedStatement over Statement in JDBC?
Answer: A
PreparedStatement pre-compiles SQL and uses parameterized queries, preventing SQL injection and improving performance.
Q.633Easy
Which JDBC method is used to retrieve the number of rows affected by an INSERT, UPDATE, or DELETE statement?
Answer: B
executeUpdate() returns an int representing the number of rows affected by the SQL statement execution.
Q.634Easy
What does the DriverManager.getConnection() method return?
Answer: B
DriverManager.getConnection() establishes a connection to the database and returns a Connection object.
Q.635Easy
In JDBC, which exception is thrown when the database driver class is not found?
Answer: B
ClassNotFoundException is thrown when Class.forName() cannot locate the JDBC driver class.
Q.636Easy
What is the purpose of the Connection.commit() method in JDBC?
Answer: B
commit() finalizes the transaction and persists all changes made since the last commit or rollback.
Q.637Medium
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.638Medium
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.639Medium
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.640Medium
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.