COMMIT command is used to permanently save any transaction into the database. It is used to end your current transaction and make permanent all changes performed in the transaction. A transaction is a sequence of SQL statements that Oracle Database treats as a single unit. This statement also erases all save points in the transaction and releases transaction locks.
When we use any DML command like INSERT, UPDATE or DELETE, the changes made by these commands are not permanent, until the current session is closed, the changes made by these commands can be rolled back. To avoid that, we use the COMMIT command to mark the changes as permanent.
7 steps to Connect our Java program to MySQL Server using JDBC API
- Import the package
- Load and Register the driver
- Create a Connection
- Create a Statement
- Execute the Query
- Process the Results
- Close the connection
We also need to include MySQL connector in our project.
Syntax of Commit
SQL Queries used in the SQL server to create the respective DB and Table
Creates a Database
CREATE DATABASE <DataBaseName>;
Creates a Table in the Current DataBase
CREATE TABLE <TableName> (usn int,, name varchar(20) , place varchar (20) );
Inserted row 1 FIRST TIME in the table.... Inserted row 2 FIRST TIME in the table.... printing data (without Rollback && without Commit ).... Ram Shyam printing data (with Rollback && without Commit ).... Empty table Inserted row 1 SECOND TIME in the table.... Inserted row 2 SECOND TIME in the table.... committed the transaction successfully.... Done Rollback.... printing data ( with Commit and then Rollback).... Ram Shyam Thank you .........
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.