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.322Medium
Which JDBC method executes UPDATE, INSERT, or DELETE statements?
Answer: C
executeUpdate() executes DML statements and returns the number of rows affected.
Q.323Medium
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.324Medium
What does ResultSetMetaData.getColumnCount() return?
Answer: B
getColumnCount() returns the total number of columns present in the ResultSet.
Q.325Medium
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.
Advertisement
Q.326Medium
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.327Medium
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.328Medium
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.329Medium
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.330Medium
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.331Medium
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.332Medium
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.333Medium
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.334Medium
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.335Medium
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().
Q.336Medium
In JDBC 2024-25, which data type mapping is incorrect for Java to SQL?
Answer: D
byte[] should map to BLOB (Binary Large Object), not CHAR. CHAR is for single character types.
Q.337Medium
What is the correct way to handle resource management in JDBC with Java 7+?
Which JDBC feature allows monitoring of database metadata like table structure and column information?
Answer: A
DatabaseMetaData (obtained from Connection.getMetaData()) provides information about the entire database like tables, columns, keys, and supported features.
Q.339Medium
A developer needs to execute the same SQL query multiple times with different parameters. Which JDBC feature should be used to optimize performance?
Answer: B
PreparedStatement pre-compiles the query and allows parameter binding, reducing overhead and improving performance for repeated executions. It also prevents SQL injection.
Q.340Medium
When using ResultSet in JDBC, which cursor type allows bidirectional movement through rows but does not reflect database changes?
Answer: B
TYPE_SCROLL_INSENSITIVE allows movement in both directions (previous, next, absolute) but doesn't reflect changes made to the database after the ResultSet was created. TYPE_SCROLL_SENSITIVE would reflect changes.