A developer wants to retrieve data from a stored procedure that returns multiple result sets and output parameters. Which approach is correct?
Answer: C
CallableStatement is specifically designed for stored procedures, supporting registerOutParameter() for output parameters and getMoreResults() for multiple result sets.
Q.682Easy
What is the difference between commit() and rollback() in JDBC transactions?
Answer: A
commit() permanently saves all changes made during the transaction, while rollback() discards all changes and reverts to the previous state.
Q.683Medium
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.684Medium
What is the correct way to handle resource management in JDBC with Java 7+?
A query execution takes 5 seconds consistently. Which JDBC optimization technique should NOT be used for this scenario?
Answer: D
If query execution itself is slow (5 seconds), the bottleneck is in database operations, not data transfer. Increasing setFetchSize() only optimizes data retrieval, not query execution.
Advertisement
Q.686Medium
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.687Hard
In a JDBC application using batch updates, what happens if one statement in the batch fails?
Answer: D
executeBatch() behavior on failure varies by database and driver. BatchUpdateException is thrown, containing update counts for each statement. Explicit transaction control is recommended.
Q.688Easy
In a JDBC application, which interface is responsible for executing SQL queries and returning ResultSet objects?
Answer: A
The Statement interface is used to execute SQL queries. Connection creates the statement, Driver manages connections, and DataSource provides connection pooling, but Statement is the actual executor.
Q.689Medium
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.690Medium
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.
Q.691Medium
In JDBC 2024-25, which exception is thrown when attempting to use a closed Connection object?
Answer: A
A SQLException (specifically a SQLNonTransientConnectionException as a subclass) is thrown when operations are attempted on a closed Connection. SQLException is the general exception for database access errors.
Q.692Hard
A Java application requires connection pooling to handle 1000+ concurrent database requests efficiently. Which JDBC component should be implemented?
Answer: B
DataSource with connection pooling frameworks (HikariCP, C3P0) efficiently manages connections by reusing them, reducing overhead. Direct getConnection() calls create new connections each time, which is inefficient for high concurrency.
Q.693Hard
In JDBC metadata operations, which method is used to retrieve information about table structure, column names, and their data types?
Answer: D
getMetaData() on ResultSet returns ResultSetMetaData which provides column information. getColumnCount() and getColumnName() are methods of ResultSetMetaData used to retrieve structure details.
Q.694Easy
What is the primary purpose of Generics in Java?
Answer: A
Generics enable type safety at compile time and eliminate the need for explicit type casting, reducing runtime errors.
Q.695Easy
Which keyword is used to declare a generic class in Java?
Answer: A
<T> is the standard syntax for declaring a generic type parameter in Java classes.
Q.696Easy
What will be the output of the following code?
List<String> list = new ArrayList<>();
list.add("Java");
System.out.println(list.get(0).length());
Answer: A
"Java" has 4 characters. The generic type ensures the element is a String, so .length() method is available without casting.
Q.697Easy
Which of the following is a valid generic method declaration?
Answer: A
The correct syntax for a generic method is: access_modifier <T> returnType methodName(T parameter). The type parameter <T> must come before the return type.
Q.698Medium
What is type erasure in Java Generics?
Answer: A
Type erasure is a mechanism where the Java compiler removes all generic type information during compilation, converting generic code to its raw type equivalent.
Q.699Medium
Which statement about wildcard generics (?) is correct?
Answer: A
Wildcards (?) represent an unknown type. Upper bound (? extends T) accepts T or its subtypes. Lower bound (? super T) accepts T or its supertypes.
Q.700Medium
What will happen when you try to create an array of generics?
List<String>[] array = new List<String>[10];
Answer: A
You cannot create arrays of generic types because of type erasure. The compiler prevents this with a compilation error.