Envision a scenario where you need to update a user’s details and also log the changes in an audit table. This operation needs to ensure data integrity and consistency. How would you achieve this using JDBC?

  • Use a database transaction to wrap both the user's update and the audit log insertion, ensuring that both operations succeed or fail together.
  • Perform the user update first, and if it succeeds, log the change in the audit table as a separate transaction.
  • Use separate database connections for the user update and audit log insertion to ensure isolation.
  • Implement a manual synchronization mechanism to ensure consistency between user updates and audit log entries.
Ensuring data integrity and consistency in this scenario requires using a database transaction to wrap both the user's update and the audit log insertion. This ensures that both operations succeed or fail together, maintaining data consistency. Performing them as separate transactions (Option 2) can lead to inconsistencies if one operation succeeds and the other fails. Using separate connections (Option 3) is not necessary when using transactions. Manual synchronization (Option 4) is error-prone and not recommended for such scenarios.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *