In a distributed system, when two databases must be updated as part of a single transaction, which transaction management technique is most appropriate?

  • Isolation (I)
  • Optimistic Concurrency Control (OCC)
  • Pessimistic Concurrency Control (PCC)
  • Two-Phase Commit (2PC)
The Two-Phase Commit (2PC) is most appropriate for managing transactions in a distributed system involving updates to multiple databases, ensuring atomicity and consistency across the distributed environment.

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 a transaction, if a part of the transaction fails, the ________ operation ensures the database reverts back to its previous state.

  • COMMIT
  • RELEASE
  • ROLLBACK
  • SAVEPOINT
The ROLLBACK operation ensures that if any part of a transaction fails, the database reverts back to its previous state, maintaining data consistency.

How should a system handle a situation where a transaction is interrupted due to a system failure?

  • Commit the partial updates
  • Ignore the interruption and proceed
  • Retry the interrupted transaction
  • Rollback the interrupted transaction
If a transaction is interrupted due to a system failure, the system should rollback the interrupted transaction to maintain consistency and avoid partial updates that could lead to data inconsistencies.

What type of exception is commonly thrown when there is a problem with a SQL query in Java?

  • ClassNotFoundException
  • IOException
  • NullPointerException
  • SQLException
A SQLException is commonly thrown when there is a problem with a SQL query in Java. It represents a database access error or other errors related to database operations.

Which Java statement is used for handling SQL exceptions?

  • finally
  • if-else
  • switch
  • try-catch
The try-catch statement is used for handling SQL exceptions in Java. It allows you to catch and handle specific exceptions that may occur during the execution of the code.

What is the main purpose of using try-catch blocks in database operations?

  • To close connections
  • To create databases
  • To execute SQL queries
  • To handle exceptions
The main purpose of using try-catch blocks in database operations is to handle exceptions that may occur during the execution of SQL queries or other database-related operations.

Which method is used to retrieve detailed information about an SQL exception?

  • getErrorCode()
  • getMessage()
  • getSQLException()
  • getSQLState()
The getErrorCode() method is used to retrieve the specific error code associated with an SQL exception, providing detailed information about the exception.

How can you handle a situation where a database connection is lost during a transaction?

  • Commit the transaction
  • Ignore the issue and proceed
  • Retry the transaction
  • Rollback the transaction
If a database connection is lost during a transaction, you can handle it by retrying the transaction, allowing for the re-establishment of the connection and completion of the operation.