What exception is thrown when a database connection fails in JDBC?
Answer: B
SQLException is thrown when database-related errors occur, including connection failures and SQL execution errors.
Q.62Easy
In JDBC, what does the executeQuery() method return?
Answer: C
executeQuery() returns a ResultSet containing the rows fetched from the database for SELECT queries.
Q.63Medium
What is the purpose of Connection.commit() in JDBC?
Answer: B
commit() saves all changes made during the current transaction permanently to the database.
Q.64Medium
Which JDBC method executes UPDATE, INSERT, or DELETE statements?
Answer: C
executeUpdate() executes DML statements and returns the number of rows affected.
Q.65Medium
What is the benefit of using PreparedStatement over Statement for repeated queries?
Answer: D
PreparedStatement offers both pre-compilation for performance and SQL injection prevention through parameterized queries.
Advertisement
Q.66Medium
What does ResultSetMetaData.getColumnCount() return?
Answer: B
getColumnCount() returns the total number of columns present in the ResultSet.
Q.67Medium
In JDBC, which class is used to retrieve database metadata information?
Answer: C
DatabaseMetaData provides information about the database, tables, columns, and other database properties.
Q.68Medium
What is the difference between execute() and executeUpdate() methods?
Answer: C
execute() returns true/false and handles any SQL, while executeUpdate() returns affected rows count for DML statements only.
Q.69Medium
Which statement should be used when you need to retrieve column information without executing multiple queries?
Answer: C
ResultSetMetaData provides column information directly from the ResultSet without additional queries.
Q.70Medium
What happens if you call next() on a ResultSet after the last row?
Answer: B
next() returns false when the cursor is positioned beyond the last row, indicating no more rows available.
Q.71Hard
Consider a scenario: A developer uses Statement with user input directly in SQL queries. What is the primary risk?
Answer: B
Direct concatenation of user input in SQL queries exposes the application to SQL injection attacks. PreparedStatement should be used instead.
Q.72Hard
In a JDBC application, when using transactions with setAutoCommit(false), what happens to intermediate savepoints if rollback() is called?
Answer: C
When rollback() is called without savepoints, all changes made since the last commit are undone and rolled back.
Q.73Hard
Which JDBC feature should be used for executing multiple SQL statements in a batch for optimal performance?
Answer: B
executeBatch() with addBatch() reduces network round-trips and improves performance for bulk operations.
Q.74Hard
In JDBC, what is the significance of setting FetchSize on a Statement when dealing with large ResultSets?
Answer: A
FetchSize controls how many rows are fetched from the database at once, optimizing performance for large datasets.
Q.75Hard
When using JDBC with Spring Framework in 2024-25, which approach is recommended for resource management?
Answer: C
JdbcTemplate in Spring Framework automatically manages JDBC resources and is the recommended approach in modern applications.
Q.76Easy
Which interface in JDBC is used to execute parameterized queries and prevent SQL injection attacks?
Answer: B
PreparedStatement is used for parameterized queries with placeholders (?), which prevents SQL injection by separating SQL logic from data.
Q.77Easy
What is the correct sequence to establish a JDBC connection in Java?
Answer: A
The correct JDBC connection sequence is: Class.forName() → DriverManager.getConnection() → Create Statement → Execute Query → Close resources.
Q.78Easy
Which method of Connection interface is used to start a transaction in JDBC?
Answer: A
setAutoCommit(false) disables auto-commit mode, allowing manual control over transactions through commit() and rollback() methods.
Q.79Easy
In JDBC, what does the BatchUpdate feature allow developers to do?
Answer: B
addBatch() and executeBatch() methods allow multiple SQL statements to be grouped and executed together, reducing network traffic and improving performance.
Q.80Medium
Which JDBC driver type is considered the most portable across different databases?
Answer: D
Type 4 drivers are pure Java implementations that directly communicate with the database, making them platform-independent and most portable.