Name

<sql:transaction>

Synopsis

The <sql:transaction> action establishes a transaction context for a set of <sql:query> and <sql:update> actions. It ensures that the database modifications performed by the nested actions are either committed or rolled back if an exception is thrown by any nested action.

The action provides a connection to the nested database actions, either from the explicitly specified data source or from the data-source configuration setting.

Syntax

<sql:transaction [dataSource="dataSource"]
  [isolation="read_committed|read_uncommitted|repeatable_read|
    serializable"]>
  <sql:query> and <sql:update> actions, and optionally other JSP elements
</sql:transaction>

Attributes

Attribute name

Java type

Dynamic value accepted

Description

dataSource
String or javax.sql.DataSource

Yes

The data source to use. If specified as a String, it can be either a JNDI path or a list of JDBC parameters as described for the data-source configuration setting.

isolation
String

Yes

The transaction isolation level. If omitted, the isolation level the data source has been configured with is used.

Example

                     <sql:transaction>
  <sql:update>
    UPDATE Account
      SET Balance = Balance - ?
      WHERE AccountNo = ?
    <sql:param value="${amount}" />
    <sql:param value="${fromAccount}" />
  </sql:update>
  <sql:update>
    UPDATE Account
      SET Balance = Balance + ?
      WHERE AccountNo = ?
    <sql:param value="${amount}" />
    <sql:param value="${toAccount}" />
  </sql:update>
</sql:transaction>

Get JavaServer Pages, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.