How can transactions be managed in JDBC to ensure data integrity?
- By using Connection.setAutoCommit(false) and manually committing transactions using Connection.commit()
- By using Connection.setAutoCommit(true) and allowing transactions to automatically commit on every SQL statement execution
- By using Connection.setReadOnly(true) to prevent any data modification, thus ensuring data integrity
- By using Connection.setTransactionIsolation() to set the desired isolation level, ensuring data consistency
In JDBC, transactions can be managed by setting auto-commit to false using Connection.setAutoCommit(false). This allows you to manually commit transactions using Connection.commit(). This approach ensures data integrity by allowing you to group multiple SQL statements into a single transaction and ensuring that they are either all executed or none at all. Setting auto-commit to true (option 2) will not provide the same level of control over transactions. Options 3 and 4 are unrelated to managing transactions in this context.
Loading...