Developing Generic Database Custom Actions

The database custom actions introduced in Chapter 9 can be used like this in a JSP page:

<ora:sqlTransaction dataSource="example">

  <ora:sqlUpdate>
    UPDATE Account SET Balance = Balance - ?
      WHERE AccountNumber = ?
    <ora:floatValue param="amount" />
    <ora:intValue param="account" />
  </ora:sqlUpdate>
  <ora:sqlUpdate>
    UPDATE Account SET Balance = Balance + ?
      WHERE AccountNumber = ?
    <ora:floatValue param="amount" />
    <ora:intValue param="account" />
  </ora:sqlUpdate>

</ora:sqlTransaction>

The database custom actions use all of the classes described previously in this chapter. A DataSource available in the application scope is used to get a Connection, and an SQLCommandBean is used to execute the SQL statement specified in the database action element body. The nested value actions create Value subclass instances and add them to a list held by the parent action tag handler. The <ora:sqlQuery> action saves the result as a Vector of Row objects in the scope specified by the page author. In this section, we first look at how the tag handlers for the <ora:sqlQuery>, <ora:sqlUpdate>, and <ora:sqlIntValue> actions are implemented. All value actions follow the same pattern as <ora:sqlIntValue>, so they are not described here. At the end of this section, we also look at the tag handler for the <ora:sqlTransatction> action to see how it provides a transaction scope for the database actions nested in its body.

The <ora:sqlQuery> and <ora:sqlUpdate> Actions

The ...

Get Java Server Pages 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.