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.22Medium
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.23Medium
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.24Medium
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.25Medium
In JDBC, what is the purpose of CallableStatement?
Answer: B
CallableStatement is used to call stored procedures and stored functions in the database.
Advertisement
Q.26Medium
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.27Medium
Which JDBC method executes UPDATE, INSERT, or DELETE statements?
Answer: C
executeUpdate() executes DML statements and returns the number of rows affected.
Q.28Medium
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.
Q.29Medium
What does ResultSetMetaData.getColumnCount() return?
Answer: B
getColumnCount() returns the total number of columns present in the ResultSet.
Q.30Medium
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.31Medium
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.32Medium
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.33Medium
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.34Medium
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.35Medium
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.36Medium
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.37Medium
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.38Medium
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.39Medium
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.40Medium
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().