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.
Loading...
Related Quiz
- What is the result of Double.POSITIVE_INFINITY == Double.POSITIVE_INFINITY in Java?
- How does Java handle overriding methods that throw exceptions?
- A ________ is used to create a client socket in Java.
- What happens to the result of a relational operation if both operands are NaN?
- What method is commonly used to execute SQL queries in Java?