Deepak wrote:
Hi folks

I guess this is off-topic. am sorry for that.

Is it possible to execute a set of SQL statements in a batch using JSP.
The db is MySQL.

I have 3 SQL statements. I want all of them to execute correctly.
If one fails the others should be rolled back.
its all or none.

Is it possible?
Yes, it's possible, even though it may be better to move complex code
like this to a servlet or other pure Java class. If you want to do it
in a JSP page, I suggest that you use the JSTL SQL actions. It has a
transaction action that wraps other SQL actions to provide the "all
or nothing" behavior you want:

  <sql:transaction>
    <sql:update sql="..." />
    <sql:update sql="..." />
  </sql:transaction>

The database and driver musy of course support transactions for this
to work. For MySQL, make sure you have a recent version, since older
versions of MySQL do not support transactions.

For more on JSTL, see <http://java.sun.com/products/jsp/jstl/>

Hans
--
Hans Bergsten                                <[EMAIL PROTECTED]>
Gefion Software                       <http://www.gefionsoftware.com/>
Author of O'Reilly's "JavaServer Pages", covering JSP 1.2 and JSTL 1.0
Details at                                    <http://TheJSPBook.com/>

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

http://archives.java.sun.com/jsp-interest.html
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.jsp
http://www.jguru.com/faq/index.jsp
http://www.jspinsider.com

Reply via email to