What is the best practice for handling SQL exceptions in a multi-tier application?

  • Catch and log the exception at the point of occurrence
  • Convert the SQL exception to a custom exception
  • Handle the exception and continue processing
  • Propagate the exception to the upper tiers
The best practice is to propagate the SQL exception to the upper tiers to allow centralized handling and logging, providing a clear separation of concerns in a multi-tier application.

In JDBC, how can you ensure that all resources are freed, even if an SQL exception occurs?

  • Close resources in the catch block
  • Implement a custom resource management mechanism
  • Resources are automatically freed in JDBC
  • Use the finally block to close resources
Using the finally block ensures that resources (like connections, statements, result sets) are closed, even if an SQL exception occurs, promoting proper resource management and avoiding leaks.

In JDBC, the __________ exception is thrown when there is a problem with the SQL syntax.

  • DBException
  • SQLException
  • SQLSyntaxException
  • SyntaxException
In JDBC, the SQLException is thrown when there is a problem with the SQL syntax.

In JDBC, what does Statement.setFetchSize(int rows) method influence?

  • Database table indexing
  • Number of rows fetched at a time
  • Query execution timeout
  • Transaction isolation level
The setFetchSize(int rows) method in JDBC influences the number of rows fetched at a time from the result set, which can impact the performance and memory usage of the application.

The _________ method is used to retrieve cookies from the request object.

  • findCookies()
  • getCookies()
  • requestCookies()
  • retrieveCookies()
The getCookies() method is used to retrieve cookies from the request object in a servlet.

To ensure that database resources are always released, use the __________ block to close connections.

  • catch
  • finally
  • release
  • try
To ensure that database resources are always released, use the finally block to close connections.

When handling multiple SQL exceptions in a method, it is common to use __________ to catch various types of exceptions.

  • catch-all
  • catch-exceptions
  • catch-multiple
  • multi-catch
When handling multiple SQL exceptions in a method, it is common to use multi-catch to catch various types of exceptions.

A __________ is a subclass of SQLException that indicates a failed connection to the database.

  • SQLDataException
  • SQLNonTransientConnectionException
  • SQLTimeoutException
  • SQLTransientConnectionException
The SQLNonTransientConnectionException is a subclass of SQLException specifically indicating a failed connection to the database.

To group multiple SQL commands and execute them as a single transaction, use the __________ feature in JDBC.

  • Batch Processing
  • Connection Pooling
  • Statement Pooling
  • Transaction
The Transaction feature in JDBC allows grouping multiple SQL commands into a single transaction for atomicity.

The method __________ is used to get the vendor-specific error code in an SQL exception.

  • getErrorCode()
  • getMessage()
  • getSQLState()
  • printStackTrace()
The getErrorCode() method is used to retrieve the vendor-specific error code from an SQL exception in JDBC.