JSTL - <sql:transaction>, rollback?

S

Sid Eaton

It's not clear from all the documentation I've read what constitutes a
reason for JSTL to decide to rollback a transaction.

For instance, I'd like to:

<sql:transaction isolation="serializable">
<sql:select>
select a counter value from a table based on some criteria FOR
UPDATE
</sql:select>

<sql:update>
update some other table based on the retrieved value above
</sql:update>

<sql:update>
update the counter value in the original table by one
</sql:update>

</sql:transaction>

sql:transaction doesn't seem to have any explicit commit or rollback
mechanism that one could manipulate in a c:if.

If we have to depend on sql:transaction to "make up its own mind"
about success or failure to determine if a commit or rollback is
appropriate, then what constitutes conditions for rollback?

For instance, if I do a SELECT ... FOR UPDATE as above and get back
zero rows, I don't want to continue the transaction, but it seems that
JSTL considers this a successful operation since no failure occurred
[returning zero rows is not a failure].

Also, if I want to prevent the web user from receiving SQL errors by
surrounding the sql:select and sql:update in a c:catch, then how
could I force a rollback?
 
C

Chris Smith

Sid said:
It's not clear from all the documentation I've read what constitutes a
reason for JSTL to decide to rollback a transaction.

Apparently, the exception will be committed if the sql:transaction tag
completes normally, and rolled back if it fails with an exception
(including SQLException or any user-defined exception). So you could
throw an exception if you need explicit rollback; but if you're sticking
with no scriptlets, then you'd need to get another tag to do so on your
behalf.

For more flexibility, remove your JDBC code from the JSP page.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
S

Sid Eaton

Chris Smith said:
Apparently, the exception will be committed if the sql:transaction tag
completes normally, and rolled back if it fails with an exception
(including SQLException or any user-defined exception). So you could
throw an exception if you need explicit rollback; but if you're sticking
with no scriptlets, then you'd need to get another tag to do so on your
behalf.

How do you throw an exception in a JSTL <sql:exception> tag?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top