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.

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.

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.

_________ 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.

In a scenario where a transaction involves multiple SQL queries, how should exceptions be handled to ensure that either all queries succeed or none do?

  • Commit each query individually
  • Commit the entire transaction only if all queries succeed
  • Ignore exceptions and continue with the transaction
  • Rollback the entire transaction on any exception
Handling exceptions in a transaction involving multiple SQL queries requires rolling back the entire transaction on any exception to ensure data consistency鈥攅ither all queries succeed, or none do.

Which method is used to batch multiple SQL statements before sending them to the database?

  • execute()
  • executeBatch()
  • executeQuery()
  • executeUpdate()
The executeBatch() method is used to batch multiple SQL statements together before sending them to the database, which can improve performance by reducing the number of round-trips.

What is the primary purpose of using a connection pool in database interactions?

  • Ensuring database security
  • Managing database connections
  • Optimizing SQL queries
  • Reducing database load
The primary purpose of using a connection pool is to manage and reuse database connections efficiently, reducing the overhead of opening and closing connections for each database interaction.

When should you choose PreparedStatement over Statement in JDBC?

  • Execute multiple queries efficiently
  • Execute parameterized queries
  • Improve query optimization
  • Simplify complex join operations
The PreparedStatement in JDBC is used to execute parameterized queries, which helps prevent SQL injection and improves performance by reusing the compiled query plan. It is suitable when you need to execute the same SQL statement multiple times with different parameters.

What is the advantage of using CallableStatement in JDBC?

  • Execute SQL queries with parameters
  • Execute stored procedures
  • Improve connection pooling
  • Streamline complex transactions
The CallableStatement in JDBC is used to execute stored procedures, providing a way to encapsulate and execute multiple SQL statements as a single unit. This enhances code modularity, reusability, and security by allowing the use of stored procedures in the database.