Java Design Pattern
Introduction to Java 10
Introduction to Java 11
Introduction to Java 12

Transaction Management In JDBC

Transaction represents a single unit of work. Transaction is a set of statements executed on a resource or resources applying ACID properties. Transactions are used to provide the data integrity over multiple users. The transaction includes the interaction between the databases and users.

ACID Properties :
  • Atomicity, it's simple either all operations in database occur, or nothing occurs.
  • Consistency, ensures that the database is in a valid state before and after the transaction.
  • Isolation, any transaction is independent of another, and your result doesn't depends of any other.
  • Durability, the result of commit a transaction must persist in a non-volatile memory even if occurs a crash or power loss.

Let's see an example of a transaction management:

import java.sql.*;
class TransactionDemo
    public static void main(String args[])throws Exception
        Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
        Statement stmt=con.createStatement();
        stmt.executeUpdate("insert into student values(101,'tapuuu','CSE')");
        stmt.executeUpdate("insert into student values(1o2,'prerik','IT')"); 

If we see the table student, (select * from student) we will see that 2 records has been added.

For this we need to create the student tables first.

 create table student
( regdno varchar(25), name char(45), branch char(55) );

About the Author

Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc