When designing an application that connects to a database, how should SQL exceptions be managed to provide meaningful feedback to the user?

  • Display the raw SQL exception message
  • Log the exception and display a user-friendly error message
  • Show a generic error message to the user
  • Terminate the application on exception
To provide meaningful feedback, log the SQL exception for debugging purposes and display a user-friendly error message to the user, avoiding the display of raw SQL exception messages that may expose sensitive information.

If an SQL exception occurs in a method that performs multiple database updates, how should the exception be handled to maintain data integrity?

  • Commit all changes made before the exception
  • Ignore the exception and continue with the remaining updates
  • Log the exception and terminate the transaction
  • Rollback all changes made before the exception
When an SQL exception occurs during multiple updates, rolling back all changes made before the exception helps maintain data integrity by ensuring either all updates succeed or none do.

When refactoring a servlet to make it more configurable, what changes are made regarding initialization parameters?

  • Introduce new initialization parameters
  • Keep the existing parameters unchanged
  • Remove all initialization parameters
  • Replace parameters with hardcoding
In the process of making a servlet more configurable, one typically introduces new initialization parameters rather than removing or replacing existing ones. This allows for greater flexibility without disrupting existing functionality.

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.

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.

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.

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.

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.

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.

_________ is a technique used to minimize the cost of repeatedly executing similar SQL queries.

  • Caching
  • Normalization
  • Sharding
  • Triggers
Caching is a technique used to minimize the cost of repeatedly executing similar SQL queries by storing the results of expensive operations and returning the cached result when the same operations occur.

Reducing the number of database ________ can significantly improve performance in a web application.

  • connections
  • indexes
  • queries
  • transactions
Reducing the number of repeated SQL queries can significantly improve performance in a web application.

Explain the role of database indexing in query optimization.

  • Depends on the size of the database and data distribution
  • Has no impact on query optimization
  • Slows down queries by adding complexity
  • Speeds up data retrieval by providing faster access
Database indexing plays a crucial role in query optimization by speeding up data retrieval. Indexes provide faster access to specific data, reducing the time it takes to execute queries, especially in scenarios with large datasets.