JSTL SQL <sql:transaction> Tag

The <sql:transaction> tag is used for transaction management. It is used to group multiple <sql:update> into common transaction. If you group multiple SQL queries in a single transaction, database is hit only once.

It is used for ensuring that the database modifications are performed by the nested actions which can be either rolled back or committed.

Example:

JSTL SQL <sql:transaction> Complete Example

Consider the below information about your MySQL database setup:

  • We are using the JDBC MySQL driver
  • We are using the test database on local machine
  • We are using the "root" as username and "1234" as password to access the test database.

To understand the basic concept, let us create a simple table Student in the test database and creates the few records in that table using command prompts as follows:

Step-1: Open the command prompt and change to the installation directory as follows:

JSTL SQL Tag21

Step-2: Login to the database using command prompt as shown below:

It will look like this:

JSTL SQL Tag22

Step-3: Create the table Students in test database as shown below:/p>

It will look like this:

JSTL SQL Tag23

Step 4: In final step you need to create few data records in Students table as shown below:

It will look like this:

JSTL SQL Tag24

Let's see the simple JSP example to understand the use of <sql:transaction> tag:

Output:

JSTL SQL Tag25
Next TopicCustom Tags