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.662Medium
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.663Medium
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.664Hard
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.665Hard
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.
Advertisement
Q.666Hard
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.667Hard
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.668Hard
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.669Easy
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.670Easy
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.671Easy
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.672Easy
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.673Medium
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.
Q.674Medium
A developer needs to execute a query that returns multiple result sets. Which Statement type should be used?
Answer: C
The execute() method returns a boolean and can handle multiple result sets via getResultSet(), getUpdateCount(), and getMoreResults() methods.
Q.675Medium
What is the purpose of Connection pooling in JDBC applications?
Answer: B
Connection pooling maintains a pool of reusable connections, reducing the overhead of creating new connections for each request, improving application performance.
Q.676Medium
Consider a scenario where a developer uses getConnection() without closing it. What is the potential impact?
Answer: B
Unclosed connections remain allocated and unavailable for other operations, eventually exhausting the connection pool and causing connection exhaustion errors.
Q.677Easy
Which exception is thrown when a JDBC driver is not found in the classpath?
Answer: B
When Class.forName() cannot locate the driver class, it throws ClassNotFoundException, indicating the driver JAR is not in the classpath.
Q.678Medium
What does the setMaxRows() method in Statement do?
Answer: A
setMaxRows() limits the number of rows returned by executeQuery(), useful for memory management when dealing with large result sets.
Q.679Medium
In a multi-threaded JDBC application, what should be the approach for Connection object usage?
Answer: B
Connection objects are not thread-safe. Each thread should obtain its own Connection from a thread-safe connection pool to avoid race conditions.
Q.680Medium
Which method in ResultSet is used to check if a column value is NULL?
Answer: B
wasNull() returns true if the last retrieved value was NULL in the database, checked after calling a getter method like getString() or getInt().