What does the executeUpdate() method return in JDBC?
Answer: B
executeUpdate() returns an integer representing the number of rows affected by INSERT, UPDATE, or DELETE operations. executeQuery() returns ResultSet.
Q.2Medium
Which interface is used to execute precompiled SQL statements in JDBC?
Answer: B
PreparedStatement is used for precompiled SQL statements with parameters. It provides better performance and prevents SQL injection compared to Statement.
Q.3Medium
What is the primary advantage of using PreparedStatement over Statement?
Answer: A
PreparedStatement offers faster execution due to precompilation and prevents SQL injection through parameterized queries using placeholders (?).
Q.4Medium
Which method must be called to move cursor to the next row in ResultSet?
Answer: A
The next() method moves the ResultSet cursor to the next row and returns true if a row exists, false if no more rows. It's essential for iterating through results.
Q.5Medium
What is Connection pooling in JDBC?
Answer: A
Connection pooling maintains a pool of reusable database connections to improve performance and reduce overhead of creating new connections repeatedly.
Advertisement
Q.6Medium
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.7Medium
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.8Medium
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.9Medium
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.10Medium
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.
Q.11Medium
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.12Medium
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.13Medium
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.14Medium
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.15Medium
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.16Medium
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.17Medium
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.18Medium
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.19Medium
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.20Medium
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.