top of page

Transaction Management in JDBC

bodarmanali66

-Transaction Management in java is required when we are dealing with relational databases.

-By default when we create a database connection, it runs in auto-commit mode.

It means that whenever we execute a query and it's completed, the commit is fired automatically.

-So every SQL query we fire is a transaction and if we are running some DML or DDL queries, the changes are getting saved into database after every SQL statement finishes.

-Sometimes we want a group of SQL queries to be part of an transaction so that we can commit them when all the queries runs fine. If we get any exception we have a choice of rollback all the queries executed as part of the transaction.



 
  • Advantages of Transaction Management:

-Fast Performance: It makes the performance fast because database is hit at the time of commit.


-In JDBC, Connection interface provides methods to manage transaction.

  1. void setAutoCommit (boolean status) : It is true by default means each transaction is committed by default.

  2. void commit() : Commits the transaction.

  3. void rollback() : Cancel the transaction.

  • Example:




19 views0 comments

Recent Posts

See All

Battle of the Backends: Java vs Node.js

Comparing Java and Node.js involves contrasting two distinct platforms commonly used in backend development. Here’s a breakdown of their...

Comments


bottom of page